mirror of
https://github.com/servo/servo.git
synced 2025-06-09 09:03:23 +00:00
Fix ./mach test-tidy --faster issue
issue number: 9778
This commit is contained in:
parent
863c905025
commit
fad0b369a7
2 changed files with 22 additions and 5 deletions
|
@ -68,6 +68,14 @@ ignored_dirs = [
|
|||
]
|
||||
|
||||
|
||||
def is_iter_empty(iterator):
|
||||
try:
|
||||
obj = iterator.next()
|
||||
return True, itertools.chain((obj,), iterator)
|
||||
except StopIteration:
|
||||
return False, iterator
|
||||
|
||||
|
||||
# A simple wrapper for iterators to show progress (note that it's inefficient for giant iterators)
|
||||
def progress_wrapper(iterator):
|
||||
list_of_stuff = list(iterator)
|
||||
|
@ -90,6 +98,9 @@ def filter_file(file_name):
|
|||
|
||||
def filter_files(start_dir, faster, progress):
|
||||
file_iter = get_file_list(start_dir, faster, ignored_dirs)
|
||||
(has_element, file_iter) = is_iter_empty(file_iter)
|
||||
if not has_element:
|
||||
raise StopIteration
|
||||
if progress:
|
||||
file_iter = progress_wrapper(file_iter)
|
||||
for file_name in file_iter:
|
||||
|
@ -100,6 +111,7 @@ def filter_files(start_dir, faster, progress):
|
|||
continue
|
||||
yield file_name
|
||||
|
||||
|
||||
EMACS_HEADER = "/* -*- Mode:"
|
||||
VIM_HEADER = "/* vim:"
|
||||
MAX_LICENSE_LINESPAN = max(len(license.splitlines()) for license in licenses)
|
||||
|
@ -554,7 +566,10 @@ def check_spec(file_name, lines):
|
|||
|
||||
|
||||
def collect_errors_for_files(files_to_check, checking_functions, line_checking_functions):
|
||||
print 'Checking files for tidiness...'
|
||||
(has_element, files_to_check) = is_iter_empty(files_to_check)
|
||||
if not has_element:
|
||||
raise StopIteration
|
||||
print '\rChecking files for tidiness...'
|
||||
for filename in files_to_check:
|
||||
with open(filename, "r") as f:
|
||||
contents = f.read()
|
||||
|
@ -569,9 +584,12 @@ def collect_errors_for_files(files_to_check, checking_functions, line_checking_f
|
|||
|
||||
|
||||
def get_wpt_files(only_changed_files, progress):
|
||||
print '\nRunning the WPT lint...'
|
||||
wpt_dir = os.path.join(".", "tests", "wpt", "web-platform-tests" + os.sep)
|
||||
file_iter = get_file_list(os.path.join(wpt_dir), only_changed_files)
|
||||
(has_element, file_iter) = is_iter_empty(file_iter)
|
||||
if not has_element:
|
||||
raise StopIteration
|
||||
print '\nRunning the WPT lint...'
|
||||
if progress:
|
||||
file_iter = progress_wrapper(file_iter)
|
||||
for f in file_iter:
|
||||
|
@ -618,12 +636,10 @@ def scan(faster=False, progress=True):
|
|||
checking_functions = (check_flake8, check_lock, check_webidl_spec, check_json)
|
||||
line_checking_functions = (check_license, check_by_line, check_toml, check_rust, check_spec)
|
||||
errors = collect_errors_for_files(files_to_check, checking_functions, line_checking_functions)
|
||||
|
||||
# wpt lint checks
|
||||
wpt_lint_errors = check_wpt_lint_errors(get_wpt_files(faster, progress))
|
||||
# collect errors
|
||||
errors = itertools.chain(errors, wpt_lint_errors)
|
||||
|
||||
error = None
|
||||
for error in errors:
|
||||
print "\r\033[94m{}\033[0m:\033[93m{}\033[0m: \033[91m{}\033[0m".format(*error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue