Bug 1291735 - Lint all files under the wpt root, not just committed ones, r=Ms2ger
This removes the git dependency
MozReview-Commit-ID: 7qqNJUOopFi
--- 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"))