From a0295b74894813fa7abbd467c1622ce09d2db59d Mon Sep 17 00:00:00 2001 From: Dhananjay Nakrani Date: Sun, 19 Apr 2015 12:42:59 -0700 Subject: [PATCH 1/3] Make tidy.py check for links to spec pages. [Issue#5730] --- python/tidy.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/python/tidy.py b/python/tidy.py index 4d24b2163cb..2288d07bdfe 100644 --- a/python/tidy.py +++ b/python/tidy.py @@ -12,6 +12,7 @@ import os import fnmatch import itertools +import re from licenseck import licenses directories_to_check = ["ports", "components", "tests"] @@ -72,6 +73,15 @@ def check_length(contents): if len(line) >= 160: yield (idx + 1, "(much) overlong line") +def check_whatwg_url(contents): + lines = contents.splitlines(True) + for idx, line in enumerate(lines): + matches = re.findall(r'whatwg.org/multipage.*#', line); + if matches: + for i, match in enumerate(matches): + parts = match.split('multipage') + if len(parts[1]) > 1 and parts[1][1] != '#': + yield (idx + 1, "URL should not point to specific WHATWG multipage page!") def check_whitespace(contents): lines = contents.splitlines(True) @@ -127,7 +137,7 @@ def scan(): all_files = collect_file_names(directories_to_check) files_to_check = filter(should_check, all_files) - checking_functions = [check_license, check_length, check_whitespace] + checking_functions = [check_license, check_length, check_whitespace, check_whatwg_url] errors = collect_errors_for_files(files_to_check, checking_functions) reftest_files = collect_file_names(reftest_directories) From 7453959426258fa85a94dc7b17373c3e6ce3a2e8 Mon Sep 17 00:00:00 2001 From: Dhananjay Nakrani Date: Sun, 19 Apr 2015 18:13:59 -0700 Subject: [PATCH 2/3] Refactor tidy.py to reduce code duplication. --- python/tidy.py | 62 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/python/tidy.py b/python/tidy.py index 2288d07bdfe..f8c34a243e0 100644 --- a/python/tidy.py +++ b/python/tidy.py @@ -67,38 +67,38 @@ def check_license(contents): yield (1, "incorrect license") -def check_length(contents): +def check_length(idx, line): + if len(line) >= 160: + yield (idx + 1, "(much) overlong line") + +def check_whatwg_url(idx, line): + matches = re.findall(r'whatwg.org/multipage.*#', line); + if matches: + for i, match in enumerate(matches): + parts = match.split('multipage') + if len(parts[1]) > 1 and parts[1][1] != '#': + yield (idx + 1, "URL should not point to specific WHATWG multipage page!") + +def check_whitespace(idx, line): + if line[-1] == "\n": + line = line[:-1] + else: + yield (idx + 1, "no newline at EOF") + + if line.endswith(" "): + yield (idx + 1, "trailing whitespace") + + if "\t" in line: + yield (idx + 1, "tab on line") + + if "\r" in line: + yield (idx + 1, "CR on line") + +def check_whitespace_url_len(contents): lines = contents.splitlines(True) for idx, line in enumerate(lines): - if len(line) >= 160: - yield (idx + 1, "(much) overlong line") - -def check_whatwg_url(contents): - lines = contents.splitlines(True) - for idx, line in enumerate(lines): - matches = re.findall(r'whatwg.org/multipage.*#', line); - if matches: - for i, match in enumerate(matches): - parts = match.split('multipage') - if len(parts[1]) > 1 and parts[1][1] != '#': - yield (idx + 1, "URL should not point to specific WHATWG multipage page!") - -def check_whitespace(contents): - lines = contents.splitlines(True) - for idx, line in enumerate(lines): - if line[-1] == "\n": - line = line[:-1] - else: - yield (idx + 1, "no newline at EOF") - - if line.endswith(" "): - yield (idx + 1, "trailing whitespace") - - if "\t" in line: - yield (idx + 1, "tab on line") - - if "\r" in line: - yield (idx + 1, "CR on line") + 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): @@ -137,7 +137,7 @@ def scan(): all_files = collect_file_names(directories_to_check) 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) reftest_files = collect_file_names(reftest_directories) From 030580e720af2b74e62281325ef7cb7cbf7ccaba Mon Sep 17 00:00:00 2001 From: Dhananjay Nakrani Date: Tue, 21 Apr 2015 10:19:29 -0700 Subject: [PATCH 3/3] Rename check_whitespace_url_len() -> check_by_line(). --- python/tidy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tidy.py b/python/tidy.py index f8c34a243e0..07eebf80677 100644 --- a/python/tidy.py +++ b/python/tidy.py @@ -94,7 +94,7 @@ def check_whitespace(idx, line): if "\r" in line: yield (idx + 1, "CR on line") -def check_whitespace_url_len(contents): +def check_by_line(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)): @@ -137,7 +137,7 @@ def scan(): all_files = collect_file_names(directories_to_check) files_to_check = filter(should_check, all_files) - checking_functions = [check_license, check_whitespace_url_len] + checking_functions = [check_license, check_by_line] errors = collect_errors_for_files(files_to_check, checking_functions) reftest_files = collect_file_names(reftest_directories)