Skip to content

Commit

Permalink
lint for usage of setTimeout (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraham authored and Ms2ger committed Feb 22, 2017
1 parent 0bceacb commit 95b0f83
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ class CRRegexp(Regexp):
error = "CR AT EOL"
description = "CR character in line separator"

class SetTimeoutRegexp(Regexp):
pattern = b"setTimeout\s*\("
error = "SET TIMEOUT"
file_extensions = [".html", ".htm", ".js", ".xht", ".xhtml", ".svg"]
description = "setTimeout used; step_timeout should typically be used instead"

class W3CTestOrgRegexp(Regexp):
pattern = b"w3c\-test\.org"
error = "W3C-TEST.ORG"
Expand All @@ -171,6 +177,7 @@ class PrintRegexp(Regexp):
[TrailingWhitespaceRegexp,
TabsRegexp,
CRRegexp,
SetTimeoutRegexp,
W3CTestOrgRegexp,
Webidl2Regexp,
ConsoleRegexp,
Expand Down
15 changes: 15 additions & 0 deletions lint/tests/test_file_lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ def test_console():
assert errors == [("PARSE-FAILED", "Unable to parse file", filename, 1)]


def test_setTimeout():
error_map = check_with_files(b"<script>setTimeout(() => 1, 10)</script>")

for (filename, (errors, kind)) in error_map.items():
check_errors(errors)

if kind == "python":
assert errors == [("PARSE-FAILED", "Unable to parse file", filename, 1)]
else:
assert errors == [('SET TIMEOUT',
'setTimeout used; step_timeout should typically be used instead',
filename,
1)]


def test_meta_timeout():
code = b"""
<html xmlns="http://www.w3.org/1999/xhtml">
Expand Down

0 comments on commit 95b0f83

Please sign in to comment.