Skip to content

Commit

Permalink
Add a lint for paths that would collide with worker tests (#141)
Browse files Browse the repository at this point in the history
Prevent adding files with .worker.html, .any.worker.html and .any.html
endings.
  • Loading branch information
jgraham authored Dec 8, 2016
1 parent 7afafbf commit 6a7de63
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ def check_path_length(repo_root, path):
return []


def check_worker_collision(repo_root, path):
endings = [(".any.html", ".any.js"),
(".any.worker.html", ".any.js"),
(".worker.html", ".worker.js")]
for path_ending, generated in endings:
if path.endswith(path_ending):
return [("WORKER COLLISION",
"path ends with %s which collides with generated tests from %s files" % (path_ending, generated),
path,
None)]
return []


def parse_whitelist(f):
"""
Parse the whitelist file given by `f`, and return the parsed structure.
Expand Down Expand Up @@ -441,7 +454,7 @@ def process_errors(path, errors):
print(ERROR_MSG % (last[0], last[1], last[0], last[1]))
return sum(itervalues(error_count))

path_lints = [check_path_length]
path_lints = [check_path_length, check_worker_collision]
file_lints = [check_regexp_line, check_parsed, check_python_ast]

if __name__ == "__main__":
Expand Down
13 changes: 13 additions & 0 deletions lint/tests/test_path_lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ def test_forbidden_path_length():
errors = check_path("/foo/", filename)
check_errors(errors)
assert errors == [("PATH LENGTH", message, filename, None)]

@pytest.mark.parametrize("path_ending,generated", [(".worker.html", ".worker.js"),
(".any.worker.html", ".any.js"),
(".any.html", ".any.js")])
def test_forbidden_path_endings(path_ending, generated):
path = "/test/test" + path_ending

message = ("path ends with %s which collides with generated tests from %s files" %
(path_ending, generated))

errors = check_path("/foo/", path)
check_errors(errors)
assert errors == [("WORKER COLLISION", message, path, None)]

0 comments on commit 6a7de63

Please sign in to comment.