mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Refactor tidy.py to reduce code duplication.
This commit is contained in:
parent
a0295b7489
commit
7453959426
1 changed files with 31 additions and 31 deletions
|
@ -67,15 +67,11 @@ def check_license(contents):
|
||||||
yield (1, "incorrect license")
|
yield (1, "incorrect license")
|
||||||
|
|
||||||
|
|
||||||
def check_length(contents):
|
def check_length(idx, line):
|
||||||
lines = contents.splitlines(True)
|
|
||||||
for idx, line in enumerate(lines):
|
|
||||||
if len(line) >= 160:
|
if len(line) >= 160:
|
||||||
yield (idx + 1, "(much) overlong line")
|
yield (idx + 1, "(much) overlong line")
|
||||||
|
|
||||||
def check_whatwg_url(contents):
|
def check_whatwg_url(idx, line):
|
||||||
lines = contents.splitlines(True)
|
|
||||||
for idx, line in enumerate(lines):
|
|
||||||
matches = re.findall(r'whatwg.org/multipage.*#', line);
|
matches = re.findall(r'whatwg.org/multipage.*#', line);
|
||||||
if matches:
|
if matches:
|
||||||
for i, match in enumerate(matches):
|
for i, match in enumerate(matches):
|
||||||
|
@ -83,9 +79,7 @@ def check_whatwg_url(contents):
|
||||||
if len(parts[1]) > 1 and parts[1][1] != '#':
|
if len(parts[1]) > 1 and parts[1][1] != '#':
|
||||||
yield (idx + 1, "URL should not point to specific WHATWG multipage page!")
|
yield (idx + 1, "URL should not point to specific WHATWG multipage page!")
|
||||||
|
|
||||||
def check_whitespace(contents):
|
def check_whitespace(idx, line):
|
||||||
lines = contents.splitlines(True)
|
|
||||||
for idx, line in enumerate(lines):
|
|
||||||
if line[-1] == "\n":
|
if line[-1] == "\n":
|
||||||
line = line[:-1]
|
line = line[:-1]
|
||||||
else:
|
else:
|
||||||
|
@ -100,6 +94,12 @@ def check_whitespace(contents):
|
||||||
if "\r" in line:
|
if "\r" in line:
|
||||||
yield (idx + 1, "CR on line")
|
yield (idx + 1, "CR on line")
|
||||||
|
|
||||||
|
def check_whitespace_url_len(contents):
|
||||||
|
lines = contents.splitlines(True)
|
||||||
|
for idx, line in enumerate(lines):
|
||||||
|
for error in itertools.chain(check_length(idx, line), check_whitespace(idx, line), check_whatwg_url(idx, line)):
|
||||||
|
yield error
|
||||||
|
|
||||||
|
|
||||||
def collect_errors_for_files(files_to_check, checking_functions):
|
def collect_errors_for_files(files_to_check, checking_functions):
|
||||||
for file_name in files_to_check:
|
for file_name in files_to_check:
|
||||||
|
@ -137,7 +137,7 @@ def scan():
|
||||||
all_files = collect_file_names(directories_to_check)
|
all_files = collect_file_names(directories_to_check)
|
||||||
files_to_check = filter(should_check, all_files)
|
files_to_check = filter(should_check, all_files)
|
||||||
|
|
||||||
checking_functions = [check_license, check_length, check_whitespace, check_whatwg_url]
|
checking_functions = [check_license, check_whitespace_url_len]
|
||||||
errors = collect_errors_for_files(files_to_check, checking_functions)
|
errors = collect_errors_for_files(files_to_check, checking_functions)
|
||||||
|
|
||||||
reftest_files = collect_file_names(reftest_directories)
|
reftest_files = collect_file_names(reftest_directories)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue