forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoFixingLineLinter.hack
More file actions
33 lines (27 loc) · 932 Bytes
/
Copy pathAutoFixingLineLinter.hack
File metadata and controls
33 lines (27 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
namespace Facebook\HHAST;
use type Facebook\HHAST\File;
use namespace HH\Lib\Str;
abstract class AutoFixingLineLinter<Terr as LineLintError>
extends LineLinter<Terr>
implements AutoFixingLinter<Terr> {
use AutoFixingLinterTrait<Terr>;
abstract public function getFixedLine(string $line): string;
final public function getFixedFile(Traversable<Terr> $errors): File {
$lines = $this->getLinesFromFile();
foreach ($errors as $err) {
$i = $err->getPosition()[0] - 1;
invariant($i >= 0, 'line number should never be negative');
$original = $lines[$i];
$lines[$i] = $this->getFixedLine($original);
}
return $this->getFile()->withContents(Str\join($lines, "\n"));
}
}