Skip to content

Commit

Permalink
Turn LinterTrait into an abstract class BaseLinter
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry authored Nov 10, 2021
1 parent c53996c commit dd1dd5c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/Linters/LinterTrait.hack → src/Linters/BaseLinter.hack
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ namespace Facebook\HHAST;
use type Facebook\HHAST\File;
use namespace HH\Lib\{C, Str};

<<__ConsistentConstruct>>
trait LinterTrait {
require implements Linter;
<<__ConsistentConstruct, __Sealed(SingleRuleLinter::class, HHClientLinter::class)>>
abstract class BaseLinter implements Linter {

public static function shouldLintFile(File $_): bool {
return true;
Expand Down
11 changes: 5 additions & 6 deletions src/Linters/HHClientLinter.hack
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use namespace HH\Lib\{C, Str, Vec};
/**
* A linter as a proxy invoking `hh_client --lint`.
*/
final class HHClientLinter implements Linter {
use LinterTrait;
final class HHClientLinter extends BaseLinter {
use SuppressibleTrait;

const type TConfig = shape();
Expand Down Expand Up @@ -63,13 +62,13 @@ final class HHClientLinter implements Linter {
|> Vec\map(
$$,
$error ==> new HHClientLintError(
$this->file,
$this->getFile(),
$error,
$this::blameCode($file_lines, $error),
),
)
|> Vec\filter($$, $error ==> {
if ($error->getLintRule()->isSuppressedForFile($this->file)) {
if ($error->getLintRule()->isSuppressedForFile($this->getFile())) {
return false;
}
$range = $error->getRange();
Expand All @@ -78,12 +77,12 @@ final class HHClientLinter implements Linter {
}
list(list($line_number, $_), $_) = $range;
$previous_line_number = $line_number - 1;
if ($this->isSuppressedForLine($this->file, $previous_line_number)) {
if ($this->isSuppressedForLine($this->getFile(), $previous_line_number)) {
return false;
}
if (
$error->getLintRule()
->isSuppressedForLine($this->file, $previous_line_number)
->isSuppressedForLine($this->getFile(), $previous_line_number)
) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Linters/Linter.hack
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Facebook\HHAST;
* Problems found by a Linter could associated with different LintRules,
* especially when the Linter is a proxy calling other linting tools.
*/
<<__Sealed(SingleRuleLinter::class, HHClientLinter::class)>>
<<__Sealed(BaseLinter::class)>>
interface Linter {
<<__Reifiable>>
abstract const type TConfig;
Expand Down
3 changes: 1 addition & 2 deletions src/Linters/SingleRuleLinter.hack
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ namespace Facebook\HHAST;
/**
* A linter that applies a single lint rule.
*/
abstract class SingleRuleLinter implements LintRule, Linter {
use LinterTrait;
abstract class SingleRuleLinter extends BaseLinter implements LintRule {
use SuppressibleTrait;

final public function getName(): string {
Expand Down

0 comments on commit dd1dd5c

Please sign in to comment.