Bug 1443887 [wpt PR 9902] - Add a lint to catch adding files that would otherwise be ignored by git., a=testonly
authorJosh Matthews <josh@joshmatthews.net>
Mon, 26 Mar 2018 15:34:14 +0000
changeset 411273 79293e8072f9f9cdb1bd974c0534ab99205d171a
parent 411272 80d4d807f8a1f866d92bf9ef1e59df0124382906
child 411274 42aecd6c1d8363a1255c2a6a4704da8a3ea52cf6
push id33749
push usercsabou@mozilla.com
push dateMon, 02 Apr 2018 10:18:51 +0000
treeherdermozilla-central@c44f60c43432 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1443887
milestone61.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 1443887 [wpt PR 9902] - Add a lint to catch adding files that would otherwise be ignored by git., a=testonly Automatic update from web-platform-testsAdd a lint to catch adding files that would otherwise be ignored by git. wpt-commits: b3b4332e7aaf7b027c11be8a0750b9136bb90a70 wpt-pr: 9902 wpt-commits: b3b4332e7aaf7b027c11be8a0750b9136bb90a70 wpt-pr: 9902
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/.gitignore
testing/web-platform/tests/tools/lint/lint.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -390313,17 +390313,17 @@
   }
  },
  "paths": {
   "./.codecov.yml": [
    "e2322808739a5977e90896b4755cfc20f4ab2046",
    "support"
   ],
   "./.gitignore": [
-   "c8dab707b3810b2e1c7d2bb03dde0d302f7647ce",
+   "c914a6a4aa7fc0ae0e948219c7949481d616d1c3",
    "support"
   ],
   "./.gitmodules": [
    "525f7d93f00f11086aabc1f652cf06623e21986c",
    "support"
   ],
   "./.pyup.yml": [
    "a276808f4f41f6243ca69600d8f9b78ca7f9ed96",
--- a/testing/web-platform/tests/.gitignore
+++ b/testing/web-platform/tests/.gitignore
@@ -1,13 +1,15 @@
 *#
 *.py[co]
 *.sw[po]
 *~
 MANIFEST.json
+!content-security-policy/support/manifest.json
+!payment-handler/manifest.json
 \#*
 _certs
 .virtualenv
 config.json
 node_modules
 scratch
 testharness_runner.html
 webdriver/.idea
--- a/testing/web-platform/tests/tools/lint/lint.py
+++ b/testing/web-platform/tests/tools/lint/lint.py
@@ -4,16 +4,17 @@ import abc
 import argparse
 import ast
 import itertools
 import json
 import os
 import re
 import subprocess
 import sys
+import tempfile
 
 from collections import defaultdict
 
 from . import fnmatch
 from .. import localpaths
 from ..gitignore.gitignore import PathFilter
 from ..wpt import testfiles
 
@@ -129,16 +130,38 @@ def check_worker_collision(repo_root, pa
 
 def check_ahem_copy(repo_root, path):
     lpath = path.lower()
     if "ahem" in lpath and lpath.endswith(".ttf"):
         return [("AHEM COPY", "Don't add extra copies of Ahem, use /fonts/Ahem.ttf", path, None)]
     return []
 
 
+def check_git_ignore(repo_root, paths):
+    errors = []
+    with tempfile.TemporaryFile('w+') as f:
+        f.write('\n'.join(paths))
+        f.seek(0)
+        try:
+            matches = subprocess.check_output(
+                ["git", "check-ignore", "--verbose", "--no-index", "--stdin"], stdin=f)
+            for match in matches.strip().split('\n'):
+                match_filter, path = match.split()
+                _, _, filter_string = match_filter.split(':')
+                # If the matching filter reported by check-ignore is a special-case exception,
+                # that's fine. Otherwise, it requires a new special-case exception.
+                if filter_string != '!' + path:
+                    errors += [("IGNORED PATH", "%s matches an ignore filter in .gitignore - "
+                                "please add a .gitignore exception" % path, path, None)]
+        except subprocess.CalledProcessError as e:
+            # Nonzero return code means that no match exists.
+            pass
+    return errors
+
+
 drafts_csswg_re = re.compile(r"https?\:\/\/drafts\.csswg\.org\/([^/?#]+)")
 w3c_tr_re = re.compile(r"https?\:\/\/www\.w3c?\.org\/TR\/([^/?#]+)")
 w3c_dev_re = re.compile(r"https?\:\/\/dev\.w3c?\.org\/[^/?#]+\/([^/?#]+)")
 
 
 def check_css_globally_unique(repo_root, paths):
     """
     Checks that CSS filenames are sufficiently unique
@@ -273,17 +296,19 @@ def filter_whitelist_errors(data, errors
 
     if not errors:
         return []
 
     whitelisted = [False for item in range(len(errors))]
 
     for i, (error_type, msg, path, line) in enumerate(errors):
         normpath = os.path.normcase(path)
-        if error_type in data:
+        # Allow whitelisting all lint errors except the IGNORED PATH lint,
+        # which explains how to fix it correctly and shouldn't be ignored.
+        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
 
     return [item for i, item in enumerate(errors) if not whitelisted[i]]
 
@@ -835,13 +860,20 @@ def lint(repo_root, paths, output_format
             for line in (ERROR_MSG % (last[0], last[1], last[0], last[1])).split("\n"):
                 logger.info(line)
     return sum(itervalues(error_count))
 
 path_lints = [check_path_length, check_worker_collision, check_ahem_copy]
 all_paths_lints = [check_css_globally_unique]
 file_lints = [check_regexp_line, check_parsed, check_python_ast, check_script_metadata]
 
+# Don't break users of the lint that don't have git installed.
+try:
+    subprocess.check_output(["git", "--version"])
+    all_paths_lints += [check_git_ignore]
+except subprocess.CalledProcessError:
+    print('No git present; skipping .gitignore lint.')
+
 if __name__ == "__main__":
     args = create_parser().parse_args()
     error_count = main(**vars(args))
     if error_count > 0:
         sys.exit(1)