Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.

Commit c53996c

Browse files
committed
Suppress lint error according to error code level markers
1 parent 14a11d4 commit c53996c

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

src/Linters/HHClientLintError.hack

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ final class HHClientLintError implements LintError {
6363
}
6464

6565
<<__Memoize>>
66-
public function getLintRule(): LintRule {
66+
public function getLintRule(): HHClientLintRule {
6767
return new HHClientLintRule($this->error['code']);
6868
}
6969

src/Linters/HHClientLinter.hack

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,35 @@ final class HHClientLinter implements Linter {
5959
),
6060
);
6161
$file_lines = Str\split($this->getFile()->getContents(), "\n");
62-
return Vec\map(
63-
$hh_client_lint_result['errors'],
64-
$error ==> new HHClientLintError(
65-
$this->file,
66-
$error,
67-
$this::blameCode($file_lines, $error),
68-
),
69-
);
62+
return $hh_client_lint_result['errors']
63+
|> Vec\map(
64+
$$,
65+
$error ==> new HHClientLintError(
66+
$this->file,
67+
$error,
68+
$this::blameCode($file_lines, $error),
69+
),
70+
)
71+
|> Vec\filter($$, $error ==> {
72+
if ($error->getLintRule()->isSuppressedForFile($this->file)) {
73+
return false;
74+
}
75+
$range = $error->getRange();
76+
if ($range is null) {
77+
return true;
78+
}
79+
list(list($line_number, $_), $_) = $range;
80+
$previous_line_number = $line_number - 1;
81+
if ($this->isSuppressedForLine($this->file, $previous_line_number)) {
82+
return false;
83+
}
84+
if (
85+
$error->getLintRule()
86+
->isSuppressedForLine($this->file, $previous_line_number)
87+
) {
88+
return false;
89+
}
90+
return true;
91+
});
7092
}
7193
}

tests/HHClientLinterTest.hack

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ final class HHClientLinterTest extends TestCase {
2424
public function getCleanExamples(): vec<(string)> {
2525
return vec[
2626
tuple("<?hh\nclass Foo {}"),
27+
tuple(
28+
'<?hh
29+
function invalid_null_check(): void {
30+
$cannot_be_null = 42;
31+
// HHAST_FIXME[5611]
32+
if ($cannot_be_null is null) {
33+
throw new Exception();
34+
}
35+
}',
36+
),
2737
];
2838
}
2939

0 commit comments

Comments
 (0)