mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Fix #6664 and add color to tidy output
This commit is contained in:
parent
e0bd80f807
commit
f039827dcd
1 changed files with 31 additions and 3 deletions
|
@ -212,7 +212,35 @@ def check_webidl_spec(file_name, contents):
|
||||||
yield 0, "No specification link found."
|
yield 0, "No specification link found."
|
||||||
|
|
||||||
|
|
||||||
|
def check_spec(file_name, contents):
|
||||||
|
base_path = "components/script/dom/"
|
||||||
|
if base_path not in file_name:
|
||||||
|
raise StopIteration
|
||||||
|
file_name = os.path.relpath(os.path.splitext(file_name)[0], base_path)
|
||||||
|
patt = re.compile("^\s*\/\/.+")
|
||||||
|
pattern = "impl<'a> %sMethods for &'a %s {" % (file_name, file_name)
|
||||||
|
contents = contents.splitlines(True)
|
||||||
|
brace_count = 0
|
||||||
|
in_impl = False
|
||||||
|
for idx, line in enumerate(contents):
|
||||||
|
if "// check-tidy: no specs after this line" in line:
|
||||||
|
break
|
||||||
|
if not patt.match(line):
|
||||||
|
if pattern.lower() in line.lower():
|
||||||
|
in_impl = True
|
||||||
|
if "fn " in line and brace_count == 1:
|
||||||
|
if "// https://" not in contents[idx - 1] and "// https://" not in contents[idx - 2]:
|
||||||
|
yield (idx + 1, "method declared in webidl is missing a comment with a specification link")
|
||||||
|
if '{' in line and in_impl:
|
||||||
|
brace_count += 1
|
||||||
|
if '}' in line and in_impl:
|
||||||
|
if brace_count == 1:
|
||||||
|
break
|
||||||
|
brace_count -= 1
|
||||||
|
|
||||||
|
|
||||||
def collect_errors_for_files(files_to_check, checking_functions):
|
def collect_errors_for_files(files_to_check, checking_functions):
|
||||||
|
base_path = "components/script/dom/"
|
||||||
for file_name in files_to_check:
|
for file_name in files_to_check:
|
||||||
with open(file_name, "r") as fp:
|
with open(file_name, "r") as fp:
|
||||||
contents = fp.read()
|
contents = fp.read()
|
||||||
|
@ -250,7 +278,7 @@ def scan():
|
||||||
all_files = collect_file_names()
|
all_files = collect_file_names()
|
||||||
files_to_check = filter(should_check, all_files)
|
files_to_check = filter(should_check, all_files)
|
||||||
|
|
||||||
checking_functions = [check_license, check_by_line, check_flake8, check_toml, check_webidl_spec]
|
checking_functions = [check_license, check_by_line, check_flake8, check_toml, check_webidl_spec, check_spec]
|
||||||
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)
|
||||||
|
@ -261,8 +289,8 @@ def scan():
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
for error in errors:
|
for error in errors:
|
||||||
print("{}:{}: {}".format(*error))
|
print "\033[94m{}\033[0m:\033[93m{}\033[0m: \033[91m{}\033[0m".format(*error)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
print("tidy reported no errors.")
|
print "\033[92mtidy reported no errors.\033[0m"
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue