99
1010namespace Facebook\HHAST ;
1111
12- use type Facebook\HHAST\File ;
13- use namespace HH\Lib\{C , Str} ;
14-
1512/**
1613 * A linter that applies a single lint rule.
1714 */
18- <<__ConsistentConstruct >>
1915abstract class SingleRuleLinter implements LintRule , Linter {
16+ use LinterTrait ;
2017
2118 final public function getName (): string {
2219 return $this -> getLinterName();
@@ -28,84 +25,4 @@ abstract class SingleRuleLinter implements LintRule, Linter {
2825
2926 abstract public function getLintErrorsAsync (): Awaitable <vec <SingleRuleLintError >>;
3027
31- public static function shouldLintFile (File $_ ): bool {
32- return true ;
33- }
34-
35- public function __construct (
36- private File $file ,
37- private ?this ::TConfig $config ,
38- ) {
39- }
40-
41- public static function newInstance (File $file , ?this ::TConfig $config ): this {
42- return new static ($file , $config );
43- }
44-
45- protected function getConfig (): ?this ::TConfig {
46- return $this -> config ;
47- }
48-
49- final public static function fromPath (string $path ): this {
50- return static :: fromPathWithConfig($path , null );
51- }
52-
53- final public static function fromPathWithConfig (
54- string $path ,
55- ?this ::TConfig $config ,
56- ): this {
57- return new static (File :: fromPath($path ), $config );
58- }
59-
60- final public function getFile (): File {
61- return $this -> file ;
62- }
63-
64- // A simple name for the linter, based on the class name
65- <<__Memoize >>
66- public function getLinterName (): string {
67- return static :: class
68- |> Str \split ($$, ' \\ ' )
69- |> C \lastx ($$)
70- |> Str \strip_suffix ($$, ' Linter' );
71- }
72-
73- /**
74- * A user can choose to ignore all errors reported by this linter for a
75- * whole file using this string as a marker
76- */
77- public function getIgnoreAllMarker (): string {
78- return LintMarkerName :: HHAST_IGNORE_ALL . ' [' . $this -> getLinterName(). ' ]' ;
79- }
80-
81- /**
82- * A user can choose to ignore a specific error reported by this linter
83- * using this string as a marker
84- */
85- public function getIgnoreSingleErrorMarker (): string {
86- return LintMarkerName :: HHAST_IGNORE_ERROR . ' [' . $this -> getLinterName(). ' ]' ;
87- }
88-
89- /**
90- * A user can choose to ignore a specific error reported by this linter
91- * using this string as a marker.
92- *
93- * The difference to HHAST_IGNORE_ERROR is that we expect this one to be
94- * fixed.
95- */
96- public function getFixmeMarker (): string {
97- return LintMarkerName :: HHAST_FIXME . ' [' . $this -> getLinterName(). ' ]' ;
98- }
99-
100- /**
101- * Is this linter error disabled for the entire file?
102- * Memoized since this should not change per run.
103- */
104- public function isLinterSuppressedForFile (): bool {
105- return C \contains_key (
106- $this -> getFile()-> lintMarkers(),
107- $this -> getIgnoreAllMarker(),
108- );
109- }
110-
11128}
0 commit comments