forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseLinter.php
78 lines (67 loc) · 1.97 KB
/
BaseLinter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?hh // strict
/*
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
namespace Facebook\HHAST\Linters;
use namespace HH\Lib\{C, Str};
<<__ConsistentConstruct>>
abstract class BaseLinter {
abstract public function getLintErrorsAsync(
): Awaitable<Traversable<LintError>>;
public static function shouldLintFile(string $_): bool {
return true;
}
public function __construct(
private string $file,
) {
}
final public function getFile(): string {
return $this->file;
}
// A simple name for the linter, based on the class name
<<__Memoize>>
public function getLinterName(): string {
return static::class
|> Str\split($$, '\\')
|> C\lastx($$)
|> Str\strip_suffix($$, 'Linter');
}
/**
* A user can choose to ignore all errors reported by this linter for a
* whole file using this string as a marker
*/
public function getIgnoreAllMarker(): string {
return 'HHAST_IGNORE_ALL['.$this->getLinterName().']';
}
/**
* A user can choose to ignore a specific error reported by this linter
* using this string as a marker
*/
public function getIgnoreSingleErrorMarker(): string {
return 'HHAST_IGNORE_ERROR['.$this->getLinterName().']';
}
/**
* A user can choose to ignore a specific error reported by this linter
* using this string as a marker.
*
* The difference to HHAST_IGNORE_ERROR is that we expect this one to be
* fixed.
*/
public function getFixmeMarker(): string {
return 'HHAST_FIXME['.$this->getLinterName().']';
}
/**
* Is this linter error disabled for the entire file?
* Memoized since this should not change per run.
*/
<<__Memoize>>
public function isLinterSuppressedForFile(): bool {
$code = \file_get_contents($this->getFile());
return Str\contains($code, $this->getIgnoreAllMarker());
}
}