forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoWhitespaceAtEndOfLineLinter.hack
More file actions
51 lines (42 loc) · 1.08 KB
/
Copy pathNoWhitespaceAtEndOfLineLinter.hack
File metadata and controls
51 lines (42 loc) · 1.08 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* 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 namespace HH\Lib\Str;
final class NoWhitespaceAtEndOfLineLinter
extends AutoFixingLineLinter<LineLintError> {
const type TConfig = shape();
<<__Override>>
public function getTitleForFix(LineLintError $_): string {
return 'Remove trailing whitespace';
}
<<__Override>>
public function getLintErrorsForLine(
string $line,
int $line_number,
): Traversable<LineLintError> {
$errs = vec[];
for ($i = Str\length($line) - 1; $i >= 0; $i--) {
$char = $line[$i];
if ($char !== ' ') {
break;
}
$errs[] = new LineLintError(
$this,
'trailing whitespace at end of line',
tuple($line_number + 1, $i + 1),
);
break;
}
return $errs;
}
<<__Override>>
public function getFixedLine(string $line): string {
return Str\trim_right($line, ' ');
}
}