This repository was archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathSuppressibleTrait.hack
73 lines (63 loc) · 1.87 KB
/
SuppressibleTrait.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
73
/*
* 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;
trait SuppressibleTrait {
abstract protected function getErrorCode(): string;
/**
* A user can choose to ignore all errors reported by this linter for a
* whole file using this string as a marker
*/
public final function getIgnoreAllMarker(): string {
return LintMarkerName::HHAST_IGNORE_ALL.
'['.
$this->getErrorCode().
']';
}
/**
* A user can choose to ignore a specific error reported by this linter
* using this string as a marker
*/
public final function getIgnoreSingleErrorMarker(): string {
return LintMarkerName::HHAST_IGNORE_ERROR.
'['.
$this->getErrorCode().
']';
}
/**
* 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 final function getFixmeMarker(): string {
return
LintMarkerName::HHAST_FIXME.'['.$this->getErrorCode().']';
}
/**
* Is this error disabled for the entire file?
*/
public final function isSuppressedForFile(File $file): bool {
return C\contains_key(
$file->errorCodesToSuppress()['whole_file'],
$this->getErrorCode(),
);
}
/** Check if this linter has been disabled by a comment on the previous line.
*/
public final function isSuppressedForLine(File $file, int $previous_line_number): bool {
$line_error_codes =
$file->errorCodesToSuppress()['single_instance'];
return (
$line_error_codes[$previous_line_number][$this->getErrorCode()] ?? null
) is nonnull;
}
}