Bug 1291735 - Lint all files under the wpt root, not just committed ones, r=Ms2ger draft
authorJames Graham <james@hoppipolla.co.uk>
Tue, 02 Aug 2016 22:28:41 +0100
changeset 396359 d6819dab68e6c176541f723cb69185499dd7526b
parent 396285 609608670ddf6e5fcce1e8bf02cf45e1bff835b3
child 396360 b4e634bb0ad05676beafcd1dfdb5530f9c6da295
push id24966
push userbmo:james@hoppipolla.co.uk
push dateWed, 03 Aug 2016 17:27:56 +0000
reviewersMs2ger
bugs1291735
milestone51.0a1
Bug 1291735 - Lint all files under the wpt root, not just committed ones, r=Ms2ger This removes the git dependency MozReview-Commit-ID: 7qqNJUOopFi
testing/web-platform/tests/tools/lint/lint.py
--- a/testing/web-platform/tests/tools/lint/lint.py
+++ b/testing/web-platform/tests/tools/lint/lint.py
@@ -34,16 +34,25 @@ you could add the following line to the 
 %s:%s"""
 
 def all_git_paths(repo_root):
     command_line = ["git", "ls-tree", "-r", "--name-only", "HEAD"]
     output = subprocess.check_output(command_line, cwd=repo_root)
     for item in output.split("\n"):
         yield item
 
+def all_filesystem_paths(repo_root):
+    for dirpath, dirnames, filenames in os.walk(repo_root):
+        for filename in filenames:
+            yield os.path.relpath(os.path.join(dirpath, filename), repo_root)
+
+def all_paths(repo_root, ignore_local):
+    fn = all_git_paths if ignore_local else all_filesystem_paths
+    for item in fn(repo_root):
+        yield item
 
 def check_path_length(repo_root, path):
     if len(path) + 1 > 150:
         return [("PATH LENGTH", "/%s longer than maximum path length (%d > 150)" % (path, len(path) + 1), None)]
     return []
 
 def set_type(error_type, errors):
     return [(error_type,) + error for error in errors]
@@ -300,22 +309,24 @@ def output_error_count(error_count):
         print("There were %d errors (%s)" % (count, by_type))
 
 def parse_args():
     parser = argparse.ArgumentParser()
     parser.add_argument("paths", nargs="*",
                         help="List of paths to lint")
     parser.add_argument("--json", action="store_true",
                         help="Output machine-readable JSON format")
+    parser.add_argument("--ignore-local", action="store_true",
+                        help="Ignore locally added files in the working directory (requires git).")
     return parser.parse_args()
 
 def main():
     repo_root = localpaths.repo_root
     args = parse_args()
-    paths = args.paths if args.paths else all_git_paths(repo_root)
+    paths = args.paths if args.paths else all_paths(repo_root, args.ignore_local)
     return lint(repo_root, paths, args.json)
 
 def lint(repo_root, paths, output_json):
     error_count = defaultdict(int)
     last = None
 
     whitelist = parse_whitelist_file(os.path.join(repo_root, "lint.whitelist"))