Package com.google.javascript.jscomp
Class AllowlistWarningsGuard
java.lang.Object
com.google.javascript.jscomp.WarningsGuard
com.google.javascript.jscomp.AllowlistWarningsGuard
- All Implemented Interfaces:
Serializable
An extension of
WarningsGuard
that provides functionality to maintain a list of warnings
(allowlist). It is subclasses' responsibility to decide what to do with the allowlist by
implementing the level
function. Warnings are defined by the name of the JS file and the
first line of warnings description.- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.google.javascript.jscomp.WarningsGuard
WarningsGuard.Priority
-
Constructor Summary
ConstructorsConstructorDescriptionAllowlistWarningsGuard
(Set<String> allowlist) This class depends on an input set that contains the allowlist. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
containWarning
(String formattedWarning) Determines whether a given warning is included in the allowlist.protected String
formatWarning
(JSError error) If subclasses want to modify the formatting, they should override #formatWarning(JSError, boolean), not this method.protected String
formatWarning
(JSError error, boolean withMetaData) static AllowlistWarningsGuard
Creates a warnings guard from a file.static String
getFirstLine
(String warning) int
The priority in which warnings guards are applied.@Nullable CheckLevel
Returns a new check level for a given error.loadAllowlistedJsWarnings
(com.google.common.io.CharSource supplier) Loads legacy warnings list from the file.Loads legacy warnings list from the file.static com.google.common.collect.ImmutableSet
<String> normalizeAllowlist
(Set<String> allowlist) Loads legacy warnings list from the set of strings.Methods inherited from class com.google.javascript.jscomp.WarningsGuard
mustRunChecks
-
Constructor Details
-
AllowlistWarningsGuard
public AllowlistWarningsGuard() -
AllowlistWarningsGuard
This class depends on an input set that contains the allowlist. The format of each allowlist string is:<file-name>:<line-number>? <warning-description>
# <optional-comment>
- Parameters:
allowlist
- The set of JS-warnings that are allowlisted. This is expected to have similar format asformatWarning(JSError)
.
-
-
Method Details
-
normalizeAllowlist
public static com.google.common.collect.ImmutableSet<String> normalizeAllowlist(Set<String> allowlist) Loads legacy warnings list from the set of strings. During development line numbers are changed very often - we just cut them and compare without ones.Also remove lines starting with "#" or are blank lines.
- Returns:
- known legacy warnings without line numbers.
-
level
Description copied from class:WarningsGuard
Returns a new check level for a given error.`null` means that this guard does not know what to do with the error. `null` can be used it chain multiple guards; if current guard returns null, then the next in the chain should process it.
- Specified by:
level
in classWarningsGuard
- Parameters:
error
- a reported error.- Returns:
- what level given error should have.
-
containWarning
Determines whether a given warning is included in the allowlist.- Parameters:
formattedWarning
- the warning formatted byformattedWarning
- Returns:
- whether the given warning is allowlisted or not.
-
getPriority
public int getPriority()Description copied from class:WarningsGuard
The priority in which warnings guards are applied. Lower means the guard will be applied sooner. Expressed on a scale of 1 to 100.- Overrides:
getPriority
in classWarningsGuard
-
fromFile
Creates a warnings guard from a file. -
loadAllowlistedJsWarnings
Loads legacy warnings list from the file.- Returns:
- The lines of the file.
-
loadAllowlistedJsWarnings
Loads legacy warnings list from the file.- Returns:
- The lines of the file.
-
formatWarning
If subclasses want to modify the formatting, they should override #formatWarning(JSError, boolean), not this method. -
formatWarning
- Parameters:
withMetaData
- If true, include metadata that's useful to humans This metadata won't be used for matching the warning.
-
getFirstLine
-