Class WarningsGuard

java.lang.Object
com.google.javascript.jscomp.WarningsGuard
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AllowlistWarningsGuard, ByPathWarningsGuard, CheckTypeSummaryWarningsGuard, ClosureUnawareCodeWarningsGuard, ComposeWarningsGuard, DiagnosticGroupPathSuppressingWarningsGuard, DiagnosticGroupWarningsGuard, J2clSuppressWarningsGuard, ShowByPathWarningsGuard, StrictWarningsGuard

public abstract class WarningsGuard extends Object implements Serializable
Class that allows to flexibly manage what to do with a reported warning/error.

Guard has several choices: - return OFF - suppress the warning/error - return WARNING - return ERROR report it with high severity - return null. Does not know what to do with it. Lets the other guard decide what to do with it.

Although the interface is very simple, it allows you easily customize what warnings you are interested in.

For example there are could be several implementations: StrictGuard - {return ERROR}. All warnings should be treat as errors. SilentGuard - {if (WARNING) return OFF}. Suppress all warnings but still fail if JS has errors. AllowlistGuard (if !allowlistErrors.contains(error) return ERROR) return error if it does not present in the allowlist.

See Also:
  • Constructor Details

    • WarningsGuard

      public WarningsGuard()
  • Method Details

    • level

      public abstract @Nullable CheckLevel level(JSError error)
      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.

      Parameters:
      error - a reported error.
      Returns:
      what level given error should have.
    • mustRunChecks

      public Tri mustRunChecks(DiagnosticGroup group)
      Do checks for `group` still need to be run if this guard is installed?
      1. TRUE: Enables one or more types in the group, so it must be checked.
      2. FALSE: Disables all types in the group, so it need not be checked.
      3. UNKNOWN: Does not affect or only partially disables the group, so checking is undecided.
      Parameters:
      group - a group to check.
    • getPriority

      protected int getPriority()
      The priority in which warnings guards are applied. Lower means the guard will be applied sooner. Expressed on a scale of 1 to 100.