Auto merge of #8044 - gilles-leblanc:issue-7998, r=Manishearth

Adds a tidy check for single-page HTML specification links

Flags links to the single-page WHATWG specification and suggests the URL
for the multi page one.

Fixes #7998

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8044)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-10-15 19:25:53 -06:00
commit 36998cd5b1

View file

@ -80,13 +80,20 @@ def check_length(file_name, idx, line):
yield (idx + 1, "Line is longer than %d characters" % max_length) yield (idx + 1, "Line is longer than %d characters" % max_length)
def check_whatwg_url(idx, line): def check_whatwg_specific_url(idx, line):
match = re.search(r"https://html\.spec\.whatwg\.org/multipage/[\w-]+\.html#([\w\:-]+)", line) match = re.search(r"https://html\.spec\.whatwg\.org/multipage/[\w-]+\.html#([\w\:-]+)", line)
if match is not None: if match is not None:
preferred_link = "https://html.spec.whatwg.org/multipage/#{}".format(match.group(1)) preferred_link = "https://html.spec.whatwg.org/multipage/#{}".format(match.group(1))
yield (idx + 1, "link to WHATWG may break in the future, use this format instead: {}".format(preferred_link)) yield (idx + 1, "link to WHATWG may break in the future, use this format instead: {}".format(preferred_link))
def check_whatwg_single_page_url(idx, line):
match = re.search(r"https://html\.spec\.whatwg\.org/#([\w\:-]+)", line)
if match is not None:
preferred_link = "https://html.spec.whatwg.org/multipage/#{}".format(match.group(1))
yield (idx + 1, "links to WHATWG single-page url, change to multi page: {}".format(preferred_link))
def check_whitespace(idx, line): def check_whitespace(idx, line):
if line[-1] == "\n": if line[-1] == "\n":
line = line[:-1] line = line[:-1]
@ -109,7 +116,8 @@ def check_by_line(file_name, contents):
errors = itertools.chain( errors = itertools.chain(
check_length(file_name, idx, line), check_length(file_name, idx, line),
check_whitespace(idx, line), check_whitespace(idx, line),
check_whatwg_url(idx, line), check_whatwg_specific_url(idx, line),
check_whatwg_single_page_url(idx, line),
) )
for error in errors: for error in errors: