Class WhitelistWarningsGuard

  • All Implemented Interfaces:
    java.io.Serializable

    public class WhitelistWarningsGuard
    extends WarningsGuard
    An extension of WarningsGuard that 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 the level function. Warnings are defined by the name of the JS file and the first line of warnings description.
    See Also:
    Serialized Form
    • Constructor Detail

      • WhitelistWarningsGuard

        public WhitelistWarningsGuard​(java.util.Set<java.lang.String> whitelist)
        This class depends on an input set that contains the white-list. The format of each white-list string is: :? #
        Parameters:
        whitelist - The set of JS-warnings that are white-listed. This is expected to have similar format as formatWarning(JSError).
    • Method Detail

      • level

        public CheckLevel level​(JSError error)
        Description copied from class: WarningsGuard
        Returns 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:
        level in class WarningsGuard
        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 by formatWarning
        Returns:
        whether the given warning is white-listed 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 class WarningsGuard
      • fromFile

        public static WhitelistWarningsGuard fromFile​(java.io.File file)
        Creates a warnings guard from a file.
      • loadWhitelistedJsWarnings

        public static java.util.Set<java.lang.String> loadWhitelistedJsWarnings​(java.io.File file)
        Loads legacy warnings list from the file.
        Returns:
        The lines of the file.
      • loadWhitelistedJsWarnings

        protected static java.util.Set<java.lang.String> loadWhitelistedJsWarnings​(com.google.common.io.InputSupplier<? extends java.io.Reader> supplier)
        Loads legacy warnings list from the file.
        Returns:
        The lines of the file.
      • formatWarning

        public static java.lang.String formatWarning​(JSError error)
      • formatWarning

        public static 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)