Skip to content

Commit

Permalink
Suppress lint error according to error code level markers
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry committed Nov 10, 2021
1 parent 14a11d4 commit c53996c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Linters/HHClientLintError.hack
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ final class HHClientLintError implements LintError {
}

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

Expand Down
38 changes: 30 additions & 8 deletions src/Linters/HHClientLinter.hack
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,35 @@ final class HHClientLinter implements Linter {
),
);
$file_lines = Str\split($this->getFile()->getContents(), "\n");
return Vec\map(
$hh_client_lint_result['errors'],
$error ==> new HHClientLintError(
$this->file,
$error,
$this::blameCode($file_lines, $error),
),
);
return $hh_client_lint_result['errors']
|> Vec\map(
$$,
$error ==> new HHClientLintError(
$this->file,
$error,
$this::blameCode($file_lines, $error),
),
)
|> Vec\filter($$, $error ==> {
if ($error->getLintRule()->isSuppressedForFile($this->file)) {
return false;
}
$range = $error->getRange();
if ($range is null) {
return true;
}
list(list($line_number, $_), $_) = $range;
$previous_line_number = $line_number - 1;
if ($this->isSuppressedForLine($this->file, $previous_line_number)) {
return false;
}
if (
$error->getLintRule()
->isSuppressedForLine($this->file, $previous_line_number)
) {
return false;
}
return true;
});
}
}
10 changes: 10 additions & 0 deletions tests/HHClientLinterTest.hack
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ final class HHClientLinterTest extends TestCase {
public function getCleanExamples(): vec<(string)> {
return vec[
tuple("<?hh\nclass Foo {}"),
tuple(
'<?hh
function invalid_null_check(): void {
$cannot_be_null = 42;
// HHAST_FIXME[5611]
if ($cannot_be_null is null) {
throw new Exception();
}
}',
),
];
}

Expand Down

0 comments on commit c53996c

Please sign in to comment.