diff options
Diffstat (limited to 'python/tidy.py')
-rw-r--r-- | python/tidy.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/python/tidy.py b/python/tidy.py index a576867b884..7e160ba6391 100644 --- a/python/tidy.py +++ b/python/tidy.py @@ -69,6 +69,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) @@ -91,6 +99,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: @@ -101,6 +112,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) @@ -555,7 +567,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() @@ -570,9 +585,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: @@ -619,12 +637,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) |