diff --git a/src/Linters/LinterTrait.hack b/src/Linters/BaseLinter.hack similarity index 92% rename from src/Linters/LinterTrait.hack rename to src/Linters/BaseLinter.hack index fec601a26..476c6d150 100644 --- a/src/Linters/LinterTrait.hack +++ b/src/Linters/BaseLinter.hack @@ -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; diff --git a/src/Linters/HHClientLinter.hack b/src/Linters/HHClientLinter.hack index 9f43601e0..cf120859b 100644 --- a/src/Linters/HHClientLinter.hack +++ b/src/Linters/HHClientLinter.hack @@ -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(); @@ -40,6 +39,7 @@ final class HHClientLinter implements Linter { ); } + <<__Override>> public async function getLintErrorsAsync( ): Awaitable> { $lines = await __Private\execute_async( @@ -63,13 +63,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(); @@ -78,12 +78,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; } diff --git a/src/Linters/Linter.hack b/src/Linters/Linter.hack index 3741210c3..3efc93cc1 100644 --- a/src/Linters/Linter.hack +++ b/src/Linters/Linter.hack @@ -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; diff --git a/src/Linters/SingleRuleLinter.hack b/src/Linters/SingleRuleLinter.hack index 68d4550b9..29de3f0c7 100644 --- a/src/Linters/SingleRuleLinter.hack +++ b/src/Linters/SingleRuleLinter.hack @@ -12,14 +12,14 @@ 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 { return $this->getLinterName(); } + <<__Override>> abstract public function getLintErrorsAsync(): Awaitable>; } diff --git a/tests/examples/MustUseOverrideAttributeLinter/overrides_grandparent.php.expect b/tests/examples/MustUseOverrideAttributeLinter/overrides_grandparent.php.expect index 8b2c724cc..1ad05bda7 100644 --- a/tests/examples/MustUseOverrideAttributeLinter/overrides_grandparent.php.expect +++ b/tests/examples/MustUseOverrideAttributeLinter/overrides_grandparent.php.expect @@ -2,6 +2,6 @@ { "blame": " public static function shouldLintFile(File $_): bool {\n return false;\n }\n", "blame_pretty": " public static function shouldLintFile(File $_): bool {", - "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>" + "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>" } ] diff --git a/tests/examples/MustUseOverrideAttributeLinter/overrides_parent.php.expect b/tests/examples/MustUseOverrideAttributeLinter/overrides_parent.php.expect index 8b2c724cc..1ad05bda7 100644 --- a/tests/examples/MustUseOverrideAttributeLinter/overrides_parent.php.expect +++ b/tests/examples/MustUseOverrideAttributeLinter/overrides_parent.php.expect @@ -2,6 +2,6 @@ { "blame": " public static function shouldLintFile(File $_): bool {\n return false;\n }\n", "blame_pretty": " public static function shouldLintFile(File $_): bool {", - "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>" + "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>" } ] diff --git a/tests/examples/MustUseOverrideAttributeLinter/with_leading_comment.php.expect b/tests/examples/MustUseOverrideAttributeLinter/with_leading_comment.php.expect index 9e1956975..9e48bb133 100644 --- a/tests/examples/MustUseOverrideAttributeLinter/with_leading_comment.php.expect +++ b/tests/examples/MustUseOverrideAttributeLinter/with_leading_comment.php.expect @@ -2,6 +2,6 @@ { "blame": " \/**\n * Set up stuff\n *\/\n public static function shouldLintFile(File $_): bool {\n return false;\n }\n", "blame_pretty": " \/**\n * Set up stuff\n *\/\n public static function shouldLintFile(File $_): bool {", - "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>" + "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>" } ] diff --git a/tests/examples/MustUseOverrideAttributeLinter/with_leading_comment_and_other_attribute.php.expect b/tests/examples/MustUseOverrideAttributeLinter/with_leading_comment_and_other_attribute.php.expect index 9a2c76df5..b604aa441 100644 --- a/tests/examples/MustUseOverrideAttributeLinter/with_leading_comment_and_other_attribute.php.expect +++ b/tests/examples/MustUseOverrideAttributeLinter/with_leading_comment_and_other_attribute.php.expect @@ -2,6 +2,6 @@ { "blame": " \/**\n * Set up stuff\n *\/\n <>\n public static function shouldLintFile(File $_): bool {\n return false;\n }\n", "blame_pretty": " \/**\n * Set up stuff\n *\/\n <>\n public static function shouldLintFile(File $_): bool {", - "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>" + "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>" } ] diff --git a/tests/examples/MustUseOverrideAttributeLinter/with_leading_newline.php.expect b/tests/examples/MustUseOverrideAttributeLinter/with_leading_newline.php.expect index c5c7347d9..f37ce8d2d 100644 --- a/tests/examples/MustUseOverrideAttributeLinter/with_leading_newline.php.expect +++ b/tests/examples/MustUseOverrideAttributeLinter/with_leading_newline.php.expect @@ -2,6 +2,6 @@ { "blame": "\n public static function shouldLintFile(File $_): bool {\n return false;\n }\n", "blame_pretty": "\n public static function shouldLintFile(File $_): bool {", - "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>" + "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>" } ] diff --git a/tests/examples/MustUseOverrideAttributeLinter/with_other_attribute.php.expect b/tests/examples/MustUseOverrideAttributeLinter/with_other_attribute.php.expect index 92a71b15f..d1b60ff14 100644 --- a/tests/examples/MustUseOverrideAttributeLinter/with_other_attribute.php.expect +++ b/tests/examples/MustUseOverrideAttributeLinter/with_other_attribute.php.expect @@ -2,6 +2,6 @@ { "blame": " <>\n public static function shouldLintFile(File $_): bool {\n return false;\n }\n", "blame_pretty": " <>\n public static function shouldLintFile(File $_): bool {", - "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>" + "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>" } ] diff --git a/tests/examples/MustUseOverrideAttributeLinter/with_other_attribute_with_value.php.expect b/tests/examples/MustUseOverrideAttributeLinter/with_other_attribute_with_value.php.expect index ef05fc892..54ee0a045 100644 --- a/tests/examples/MustUseOverrideAttributeLinter/with_other_attribute_with_value.php.expect +++ b/tests/examples/MustUseOverrideAttributeLinter/with_other_attribute_with_value.php.expect @@ -2,6 +2,6 @@ { "blame": " <>\n public static function shouldLintFile(File $_): bool {\n return false;\n }\n", "blame_pretty": " <>\n public static function shouldLintFile(File $_): bool {", - "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>" + "description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>" } ]