Bug 1634070 [wpt PR 23319] - Rename lint.whitelist to lint.ignore, a=testonly
authorStephen McGruer <smcgruer@chromium.org>
Wed, 13 May 2020 03:58:27 +0000
changeset 531023 aaa4b8916c4687c0db21225ccaa15d607fdda80a
parent 531022 c260a1c92bb9101d4f540b5db432cd4b017f1932
child 531024 564102394fc51865fcd91eb2c695ada3796e57f9
push id37435
push userapavel@mozilla.com
push dateWed, 20 May 2020 15:28:23 +0000
treeherdermozilla-central@5415da14ec9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1634070, 23319
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1634070 [wpt PR 23319] - Rename lint.whitelist to lint.ignore, a=testonly Automatic update from web-platform-tests Rename lint.whitelist to lint.ignore (#23319) See the RFC: https://github.com/web-platform-tests/rfcs/blob/master/rfcs/rename_lint_whitelist.md -- wpt-commits: 622c9625dddfdef0c6dfafa8fa00d5119db50201 wpt-pr: 23319
testing/web-platform/tests/lint.ignore
testing/web-platform/tests/lint.whitelist
testing/web-platform/tests/tools/lint/lint.py
testing/web-platform/tests/tools/lint/tests/dummy/lint.ignore
testing/web-platform/tests/tools/lint/tests/dummy/lint.whitelist
testing/web-platform/tests/tools/lint/tests/test_lint.py
rename from testing/web-platform/tests/lint.whitelist
rename to testing/web-platform/tests/lint.ignore
--- a/testing/web-platform/tests/tools/lint/lint.py
+++ b/testing/web-platform/tests/tools/lint/lint.py
@@ -36,17 +36,22 @@ if MYPY:
     from typing import Optional
     from typing import Sequence
     from typing import Set
     from typing import Text
     from typing import Tuple
     from typing import Type
     from typing import Union
 
-    Whitelist = Dict[Text, Dict[Text, Set[Optional[int]]]]
+    # The Ignorelist is a two level dictionary. The top level is indexed by
+    # error names (e.g. 'TRAILING WHITESPACE'). Each of those then has a map of
+    # file patterns (e.g. 'foo/*') to a set of specific line numbers for the
+    # exception. The line numbers are optional; if missing the entire file
+    # ignores the error.
+    Ignorelist = Dict[Text, Dict[Text, Set[Optional[int]]]]
 
 
 logger = None  # type: Optional[logging.Logger]
 
 def setup_logging(prefix=False):
     # type: (bool) -> None
     global logger
     if logger is None:
@@ -70,22 +75,22 @@ def setup_logging(prefix=False):
 
 setup_logging()
 
 
 ERROR_MSG = """You must fix all errors; for details on how to fix them, see
 https://web-platform-tests.org/writing-tests/lint-tool.html
 
 However, instead of fixing a particular error, it's sometimes
-OK to add a line to the lint.whitelist file in the root of the
+OK to add a line to the lint.ignore file in the root of the
 web-platform-tests directory to make the lint tool ignore it.
 
 For example, to make the lint tool ignore all '%s'
 errors in the %s file,
-you could add the following line to the lint.whitelist file.
+you could add the following line to the lint.ignore file.
 
 %s: %s"""
 
 def all_filesystem_paths(repo_root, subdir=None):
     # type: (str, Optional[str]) -> Iterable[str]
     path_filter = PathFilter(repo_root, extras=[str(".git/")])
     if subdir:
         expanded_path = subdir
@@ -313,24 +318,27 @@ def check_css_globally_unique(repo_root,
                     context2 = (name, ", ".join(sorted(colliding)))
 
                     for x in colliding:
                         errors.append(rule_class.error(x, context2))
 
     return errors
 
 
-def parse_whitelist(f):
-    # type: (IO[bytes]) -> Tuple[Whitelist, Set[Text]]
+def parse_ignorelist(f):
+    # type: (IO[bytes]) -> Tuple[Ignorelist, Set[Text]]
     """
-    Parse the whitelist file given by `f`, and return the parsed structure.
+    Parse the ignorelist file given by `f`, and return the parsed structure.
+
+    :returns: a tuple of an Ignorelist and a set of files that are completely
+              skipped by the linter (i.e. have a '*' entry).
     """
 
-    data = defaultdict(lambda:defaultdict(set))  # type: Whitelist
-    ignored_files = set()  # type: Set[Text]
+    data = defaultdict(lambda:defaultdict(set))  # type: Ignorelist
+    skipped_files = set()  # type: Set[Text]
 
     for line in f:
         line = line.strip()
         if not line or line.startswith("#"):
             continue
         parts = [item.strip() for item in line.split(":")]
 
         if len(parts) == 2:
@@ -339,47 +347,47 @@ def parse_whitelist(f):
         else:
             error_types_s, file_match, line_number_s = parts
             line_number = int(line_number_s)
 
         error_types = {item.strip() for item in error_types_s.split(",")}
         file_match = os.path.normcase(file_match)
 
         if "*" in error_types:
-            ignored_files.add(file_match)
+            skipped_files.add(file_match)
         else:
             for error_type in error_types:
                 data[error_type][file_match].add(line_number)
 
-    return data, ignored_files
+    return data, skipped_files
 
 
-def filter_whitelist_errors(data, errors):
-    # type: (Whitelist, Sequence[rules.Error]) -> List[rules.Error]
+def filter_ignorelist_errors(data, errors):
+    # type: (Ignorelist, Sequence[rules.Error]) -> List[rules.Error]
     """
-    Filter out those errors that are whitelisted in `data`.
+    Filter out those errors that are ignored in `data`.
     """
 
     if not errors:
         return []
 
-    whitelisted = [False for item in range(len(errors))]
+    skipped = [False for item in range(len(errors))]
 
     for i, (error_type, msg, path, line) in enumerate(errors):
         normpath = os.path.normcase(path)
-        # Allow whitelisting all lint errors except the IGNORED PATH lint,
-        # which explains how to fix it correctly and shouldn't be ignored.
+        # Allow skipping all lint errors except the IGNORED PATH lint,
+        # which explains how to fix it correctly and shouldn't be skipped.
         if error_type in data and error_type != "IGNORED PATH":
             wl_files = data[error_type]
             for file_match, allowed_lines in iteritems(wl_files):
                 if None in allowed_lines or line in allowed_lines:
                     if fnmatch.fnmatchcase(normpath, file_match):
-                        whitelisted[i] = True
+                        skipped[i] = True
 
-    return [item for i, item in enumerate(errors) if not whitelisted[i]]
+    return [item for i, item in enumerate(errors) if not skipped[i]]
 
 
 regexps = [item() for item in  # type: ignore
            [rules.TrailingWhitespaceRegexp,
             rules.TabsRegexp,
             rules.CRRegexp,
             rules.SetTimeoutRegexp,
             rules.W3CTestOrgRegexp,
@@ -800,17 +808,17 @@ def lint_paths(kwargs, wpt_root):
 
     elif kwargs[str("all")]:
         paths = list(all_filesystem_paths(wpt_root))
     else:
         changed_paths = changed_files(wpt_root)
         force_all = False
         for path in changed_paths:
             path = path.replace(os.path.sep, "/")
-            if path == "lint.whitelist" or path.startswith("tools/lint/"):
+            if path == "lint.ignore" or path.startswith("tools/lint/"):
                 force_all = True
                 break
         paths = (list(changed_paths) if not force_all  # type: ignore
                  else list(all_filesystem_paths(wpt_root)))
 
     return paths
 
 
@@ -854,54 +862,54 @@ def main(**kwargs):
     return lint(repo_root, paths, output_format, str(ignore_glob))
 
 
 def lint(repo_root, paths, output_format, ignore_glob=str()):
     # type: (str, List[str], str, str) -> int
     error_count = defaultdict(int)  # type: Dict[Text, int]
     last = None
 
-    with open(os.path.join(repo_root, "lint.whitelist")) as f:
-        whitelist, ignored_files = parse_whitelist(f)
+    with open(os.path.join(repo_root, "lint.ignore")) as f:
+        ignorelist, skipped_files = parse_ignorelist(f)
 
     if ignore_glob:
-        ignored_files.add(ignore_glob)
+        skipped_files.add(ignore_glob)
 
     output_errors = {"json": output_errors_json,
                      "markdown": output_errors_markdown,
                      "normal": output_errors_text}[output_format]
 
     def process_errors(errors):
         # type: (List[rules.Error]) -> Optional[Tuple[Text, Text]]
         """
         Filters and prints the errors, and updates the ``error_count`` object.
 
         :param errors: a list of error tuples (error type, message, path, line number)
         :returns: ``None`` if there were no errors, or
                   a tuple of the error type and the path otherwise
         """
 
-        errors = filter_whitelist_errors(whitelist, errors)
+        errors = filter_ignorelist_errors(ignorelist, errors)
 
         if not errors:
             return None
 
         output_errors(errors)
         for error_type, error, path, line in errors:
             error_count[error_type] += 1
 
         return (errors[-1][0], path)
 
     for path in paths[:]:
         abs_path = os.path.join(repo_root, path)
         if not os.path.exists(abs_path):
             paths.remove(path)
             continue
 
-        if any(fnmatch.fnmatch(path, file_match) for file_match in ignored_files):
+        if any(fnmatch.fnmatch(path, file_match) for file_match in skipped_files):
             paths.remove(path)
             continue
 
         errors = check_path(repo_root, path)
         last = process_errors(errors) or last
 
         if not os.path.isdir(abs_path):
             with open(abs_path, 'rb') as f:
rename from testing/web-platform/tests/tools/lint/tests/dummy/lint.whitelist
rename to testing/web-platform/tests/tools/lint/tests/dummy/lint.ignore
--- a/testing/web-platform/tests/tools/lint/tests/test_lint.py
+++ b/testing/web-platform/tests/tools/lint/tests/test_lint.py
@@ -3,62 +3,62 @@ from __future__ import unicode_literals
 import os
 import sys
 
 import mock
 import six
 
 from ...localpaths import repo_root
 from .. import lint as lint_mod
-from ..lint import filter_whitelist_errors, parse_whitelist, lint, create_parser
+from ..lint import filter_ignorelist_errors, parse_ignorelist, lint, create_parser
 
 _dummy_repo = os.path.join(os.path.dirname(__file__), "dummy")
 
 def _mock_lint(name, **kwargs):
     wrapped = getattr(lint_mod, name)
     return mock.patch(lint_mod.__name__ + "." + name, wraps=wrapped, **kwargs)
 
 
-def test_filter_whitelist_errors():
-    whitelist = {
+def test_filter_ignorelist_errors():
+    ignorelist = {
         'CONSOLE': {
             'svg/*': {12}
         },
         'INDENT TABS': {
             'svg/*': {None}
         }
     }
-    # parse_whitelist normalises the case/path of the match string so need to do the same
-    whitelist = {e: {os.path.normcase(k): v for k, v in p.items()}
-                 for e, p in whitelist.items()}
-    # paths passed into filter_whitelist_errors are always Unix style
+    # parse_ignorelist normalises the case/path of the match string so need to do the same
+    ignorelist = {e: {os.path.normcase(k): v for k, v in p.items()}
+                 for e, p in ignorelist.items()}
+    # paths passed into filter_ignorelist_errors are always Unix style
     filteredfile = 'svg/test.html'
     unfilteredfile = 'html/test.html'
     # Tests for passing no errors
-    filtered = filter_whitelist_errors(whitelist, [])
+    filtered = filter_ignorelist_errors(ignorelist, [])
     assert filtered == []
-    filtered = filter_whitelist_errors(whitelist, [])
+    filtered = filter_ignorelist_errors(ignorelist, [])
     assert filtered == []
     # Tests for filtering on file and line number
-    filtered = filter_whitelist_errors(whitelist, [['CONSOLE', '', filteredfile, 12]])
+    filtered = filter_ignorelist_errors(ignorelist, [['CONSOLE', '', filteredfile, 12]])
     assert filtered == []
-    filtered = filter_whitelist_errors(whitelist, [['CONSOLE', '', unfilteredfile, 12]])
+    filtered = filter_ignorelist_errors(ignorelist, [['CONSOLE', '', unfilteredfile, 12]])
     assert filtered == [['CONSOLE', '', unfilteredfile, 12]]
-    filtered = filter_whitelist_errors(whitelist, [['CONSOLE', '', filteredfile, 11]])
+    filtered = filter_ignorelist_errors(ignorelist, [['CONSOLE', '', filteredfile, 11]])
     assert filtered == [['CONSOLE', '', filteredfile, 11]]
     # Tests for filtering on just file
-    filtered = filter_whitelist_errors(whitelist, [['INDENT TABS', '', filteredfile, 12]])
+    filtered = filter_ignorelist_errors(ignorelist, [['INDENT TABS', '', filteredfile, 12]])
     assert filtered == []
-    filtered = filter_whitelist_errors(whitelist, [['INDENT TABS', '', filteredfile, 11]])
+    filtered = filter_ignorelist_errors(ignorelist, [['INDENT TABS', '', filteredfile, 11]])
     assert filtered == []
-    filtered = filter_whitelist_errors(whitelist, [['INDENT TABS', '', unfilteredfile, 11]])
+    filtered = filter_ignorelist_errors(ignorelist, [['INDENT TABS', '', unfilteredfile, 11]])
     assert filtered == [['INDENT TABS', '', unfilteredfile, 11]]
 
 
-def test_parse_whitelist():
+def test_parse_ignorelist():
     input_buffer = six.StringIO("""
 # Comment
 CR AT EOL: svg/import/*
 CR AT EOL: streams/resources/test-utils.js
 
 INDENT TABS: .gitmodules
 INDENT TABS: app-uri/*
 INDENT TABS: svg/*
@@ -95,20 +95,20 @@ CR AT EOL, INDENT TABS: html/test2.js: 4
             'streams/resources/test-utils.js': {None},
             'svg/import/*': {None},
             'html/test.js': {None},
             'html/test2.js': {42},
         }
     }
     expected_data = {e: {os.path.normcase(k): v for k, v in p.items()}
                      for e, p in expected_data.items()}
-    expected_ignored = {os.path.normcase(x) for x in {"*.pdf", "resources/*", "*.png"}}
-    data, ignored = parse_whitelist(input_buffer)
+    expected_skipped = {os.path.normcase(x) for x in {"*.pdf", "resources/*", "*.png"}}
+    data, skipped_files = parse_ignorelist(input_buffer)
     assert data == expected_data
-    assert ignored == expected_ignored
+    assert skipped_files == expected_skipped
 
 
 def test_lint_no_files(caplog):
     rv = lint(_dummy_repo, [], "normal")
     assert rv == 0
     assert caplog.text == ""