-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinterTrait.hack
72 lines (57 loc) · 1.68 KB
/
LinterTrait.hack
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
/*
* 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;
use type Facebook\HHAST\File;
use namespace HH\Lib\{C, Str};
<<__ConsistentConstruct>>
trait LinterTrait {
require implements Linter;
public static function shouldLintFile(File $_): bool {
return true;
}
private File $file;
private ?this::TConfig $config;
private function __construct(File $file, ?this::TConfig $config) {
$this->file = $file;
$this->config = $config;
}
public static function newInstance(File $file, ?this::TConfig $config): this {
return new static($file, $config);
}
protected function getConfig(): ?this::TConfig {
return $this->config;
}
final public static function fromPath(string $path): this {
return static::fromPathWithConfig($path, null);
}
final public static function fromPathWithConfig(
string $path,
?this::TConfig $config,
): this {
return new static(File::fromPath($path), $config);
}
final public function getFile(): File {
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');
}
public final function getErrorCode(): string {
return $this->getLinterName();
}
abstract protected function isSuppressedForFile(File $file): bool;
public function isLinterSuppressedForFile(): bool {
return $this->isSuppressedForFile($this->getFile());
}
}