Package com.google.javascript.jscomp
Class AllowlistWarningsGuard
- java.lang.Object
-
- com.google.javascript.jscomp.WarningsGuard
-
- com.google.javascript.jscomp.AllowlistWarningsGuard
-
- All Implemented Interfaces:
java.io.Serializable
@GwtIncompatible("java.io, java.util.regex") public class AllowlistWarningsGuard extends WarningsGuardAn extension ofWarningsGuardthat provides functionality to maintain a list of warnings (white-list). It is subclasses' responsibility to decide what to do with the white-list by implementing thelevelfunction. Warnings are defined by the name of the JS file and the first line of warnings description.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAllowlistWarningsGuard.AllowlistBuilderAllowlist builder-
Nested classes/interfaces inherited from class com.google.javascript.jscomp.WarningsGuard
WarningsGuard.Priority
-
-
Constructor Summary
Constructors Constructor Description AllowlistWarningsGuard()AllowlistWarningsGuard(java.util.Set<java.lang.String> allowlist)This class depends on an input set that contains the white-list.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancontainWarning(java.lang.String formattedWarning)Determines whether a given warning is included in the white-list.protected java.lang.StringformatWarning(JSError error)If subclasses want to modify the formatting, they should override #formatWarning(JSError, boolean), not this method.protected java.lang.StringformatWarning(JSError error, boolean withMetaData)static AllowlistWarningsGuardfromFile(java.io.File file)Creates a warnings guard from a file.static java.lang.StringgetFirstLine(java.lang.String warning)intgetPriority()The priority in which warnings guards are applied.CheckLevellevel(JSError error)Returns a new check level for a given error.protected static java.util.Set<java.lang.String>loadAllowlistedJsWarnings(com.google.common.io.CharSource supplier)Loads legacy warnings list from the file.static java.util.Set<java.lang.String>loadAllowlistedJsWarnings(java.io.File file)Loads legacy warnings list from the file.protected java.util.Set<java.lang.String>normalizeAllowlist(java.util.Set<java.lang.String> allowlist)Loads legacy warnings list from the set of strings.-
Methods inherited from class com.google.javascript.jscomp.WarningsGuard
disables, enables
-
-
-
-
Constructor Detail
-
AllowlistWarningsGuard
public AllowlistWarningsGuard()
-
AllowlistWarningsGuard
public AllowlistWarningsGuard(java.util.Set<java.lang.String> allowlist)
This class depends on an input set that contains the white-list. The format of each white-list string is:<file-name>:<line-number>? <warning-description># <optional-comment>- Parameters:
allowlist- The set of JS-warnings that are white-listed. This is expected to have similar format asformatWarning(JSError).
-
-
Method Detail
-
normalizeAllowlist
protected java.util.Set<java.lang.String> normalizeAllowlist(java.util.Set<java.lang.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.- Returns:
- known legacy warnings without line numbers.
-
level
public CheckLevel level(JSError error)
Description copied from class:WarningsGuardReturns a new check level for a given error. OFF - suppress it, ERROR - report as error. null means that this guard does not know what to do with the error. Null is extremely helpful when you have a chain of guards. If current guard returns null, then the next in the chain should process it.- Specified by:
levelin classWarningsGuard- Parameters:
error- a reported error.- Returns:
- what level given error should have.
-
containWarning
protected boolean containWarning(java.lang.String formattedWarning)
Determines whether a given warning is included in the white-list.- Parameters:
formattedWarning- the warning formatted byformattedWarning- Returns:
- whether the given warning is white-listed or not.
-
getPriority
public int getPriority()
Description copied from class:WarningsGuardThe priority in which warnings guards are applied. Lower means the guard will be applied sooner. Expressed on a scale of 1 to 100.- Overrides:
getPriorityin classWarningsGuard
-
fromFile
public static AllowlistWarningsGuard fromFile(java.io.File file)
Creates a warnings guard from a file.
-
loadAllowlistedJsWarnings
public static java.util.Set<java.lang.String> loadAllowlistedJsWarnings(java.io.File file)
Loads legacy warnings list from the file.- Returns:
- The lines of the file.
-
loadAllowlistedJsWarnings
protected static java.util.Set<java.lang.String> loadAllowlistedJsWarnings(com.google.common.io.CharSource supplier)
Loads legacy warnings list from the file.- Returns:
- The lines of the file.
-
formatWarning
protected java.lang.String formatWarning(JSError error)
If subclasses want to modify the formatting, they should override #formatWarning(JSError, boolean), not this method.
-
formatWarning
protected java.lang.String formatWarning(JSError error, boolean withMetaData)
- Parameters:
withMetaData- If true, include metadata that's useful to humans This metadata won't be used for matching the warning.
-
getFirstLine
public static java.lang.String getFirstLine(java.lang.String warning)
-
-