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

Commit d629d29

Browse files
authored
Turn LinterTrait into an abstract class BaseLinter
1 parent c53996c commit d629d29

11 files changed

+18
-19
lines changed

src/Linters/LinterTrait.hack renamed to src/Linters/BaseLinter.hack

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ namespace Facebook\HHAST;
1212
use type Facebook\HHAST\File;
1313
use namespace HH\Lib\{C, Str};
1414

15-
<<__ConsistentConstruct>>
16-
trait LinterTrait {
17-
require implements Linter;
15+
<<__ConsistentConstruct, __Sealed(SingleRuleLinter::class, HHClientLinter::class)>>
16+
abstract class BaseLinter implements Linter {
1817

1918
public static function shouldLintFile(File $_): bool {
2019
return true;

src/Linters/HHClientLinter.hack

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use namespace HH\Lib\{C, Str, Vec};
1515
/**
1616
* A linter as a proxy invoking `hh_client --lint`.
1717
*/
18-
final class HHClientLinter implements Linter {
19-
use LinterTrait;
18+
final class HHClientLinter extends BaseLinter {
2019
use SuppressibleTrait;
2120

2221
const type TConfig = shape();
@@ -40,6 +39,7 @@ final class HHClientLinter implements Linter {
4039
);
4140
}
4241

42+
<<__Override>>
4343
public async function getLintErrorsAsync(
4444
): Awaitable<vec<HHClientLintError>> {
4545
$lines = await __Private\execute_async(
@@ -63,13 +63,13 @@ final class HHClientLinter implements Linter {
6363
|> Vec\map(
6464
$$,
6565
$error ==> new HHClientLintError(
66-
$this->file,
66+
$this->getFile(),
6767
$error,
6868
$this::blameCode($file_lines, $error),
6969
),
7070
)
7171
|> Vec\filter($$, $error ==> {
72-
if ($error->getLintRule()->isSuppressedForFile($this->file)) {
72+
if ($error->getLintRule()->isSuppressedForFile($this->getFile())) {
7373
return false;
7474
}
7575
$range = $error->getRange();
@@ -78,12 +78,12 @@ final class HHClientLinter implements Linter {
7878
}
7979
list(list($line_number, $_), $_) = $range;
8080
$previous_line_number = $line_number - 1;
81-
if ($this->isSuppressedForLine($this->file, $previous_line_number)) {
81+
if ($this->isSuppressedForLine($this->getFile(), $previous_line_number)) {
8282
return false;
8383
}
8484
if (
8585
$error->getLintRule()
86-
->isSuppressedForLine($this->file, $previous_line_number)
86+
->isSuppressedForLine($this->getFile(), $previous_line_number)
8787
) {
8888
return false;
8989
}

src/Linters/Linter.hack

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Facebook\HHAST;
1515
* Problems found by a Linter could associated with different LintRules,
1616
* especially when the Linter is a proxy calling other linting tools.
1717
*/
18-
<<__Sealed(SingleRuleLinter::class, HHClientLinter::class)>>
18+
<<__Sealed(BaseLinter::class)>>
1919
interface Linter {
2020
<<__Reifiable>>
2121
abstract const type TConfig;

src/Linters/SingleRuleLinter.hack

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace Facebook\HHAST;
1212
/**
1313
* A linter that applies a single lint rule.
1414
*/
15-
abstract class SingleRuleLinter implements LintRule, Linter {
16-
use LinterTrait;
15+
abstract class SingleRuleLinter extends BaseLinter implements LintRule {
1716
use SuppressibleTrait;
1817

1918
final public function getName(): string {
2019
return $this->getLinterName();
2120
}
2221

22+
<<__Override>>
2323
abstract public function getLintErrorsAsync(): Awaitable<vec<SingleRuleLintError>>;
2424

2525
}

tests/examples/MustUseOverrideAttributeLinter/overrides_grandparent.php.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
"blame": " public static function shouldLintFile(File $_): bool {\n return false;\n }\n",
44
"blame_pretty": " public static function shouldLintFile(File $_): bool {",
5-
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>"
5+
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>"
66
}
77
]

tests/examples/MustUseOverrideAttributeLinter/overrides_parent.php.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
"blame": " public static function shouldLintFile(File $_): bool {\n return false;\n }\n",
44
"blame_pretty": " public static function shouldLintFile(File $_): bool {",
5-
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>"
5+
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>"
66
}
77
]

tests/examples/MustUseOverrideAttributeLinter/with_leading_comment.php.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
"blame": " \/**\n * Set up stuff\n *\/\n public static function shouldLintFile(File $_): bool {\n return false;\n }\n",
44
"blame_pretty": " \/**\n * Set up stuff\n *\/\n public static function shouldLintFile(File $_): bool {",
5-
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>"
5+
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>"
66
}
77
]

tests/examples/MustUseOverrideAttributeLinter/with_leading_comment_and_other_attribute.php.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
"blame": " \/**\n * Set up stuff\n *\/\n <<HerpDerp>>\n public static function shouldLintFile(File $_): bool {\n return false;\n }\n",
44
"blame_pretty": " \/**\n * Set up stuff\n *\/\n <<HerpDerp>>\n public static function shouldLintFile(File $_): bool {",
5-
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>"
5+
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>"
66
}
77
]

tests/examples/MustUseOverrideAttributeLinter/with_leading_newline.php.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
"blame": "\n public static function shouldLintFile(File $_): bool {\n return false;\n }\n",
44
"blame_pretty": "\n public static function shouldLintFile(File $_): bool {",
5-
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>"
5+
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>"
66
}
77
]

tests/examples/MustUseOverrideAttributeLinter/with_other_attribute.php.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
"blame": " <<Foo>>\n public static function shouldLintFile(File $_): bool {\n return false;\n }\n",
44
"blame_pretty": " <<Foo>>\n public static function shouldLintFile(File $_): bool {",
5-
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\SingleRuleLinter::shouldLintFile() without <<__Override>>"
5+
"description": "Foo::shouldLintFile() overrides Facebook\\HHAST\\BaseLinter::shouldLintFile() without <<__Override>>"
66
}
77
]

0 commit comments

Comments
 (0)