Commit 62f87169 authored by Dan Beam's avatar Dan Beam Committed by Commit Bot

web_dev_style: fix bug in which $i18n{camelCaseKeys} trips presubmit

There's a rule in the web styleguide[1] about CSS .classes-use-dashes.
Our brilliant presubmit uses regex and is silly. So strip $i18n{...}
from the cases that have it so the presubmit still works, but just don't
show line contents in those cases.

[1] https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/web.md

Bug: None
Change-Id: Ic5aaa0caa3087465b6b40946e113b52ddf635f8c
Reviewed-on: https://chromium-review.googlesource.com/785795
Commit-Queue: Dan Beam (no longer on Chrome) <dbeam@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519567}
parent 832a9b3e
......@@ -16,13 +16,20 @@ class HtmlChecker(object):
self.file_filter = file_filter
def ClassesUseDashFormCheck(self, line_number, line):
regex = self.input_api.re.compile("""
msg = "Classes should use dash-form."
re = self.input_api.re
class_regex = re.compile("""
(?:^|\s) # start of line or whitespace
(class="[^"]*[A-Z_][^"]*") # class contains caps or '_'
""",
self.input_api.re.VERBOSE)
return regex_check.RegexCheck(self.input_api.re, line_number, line, regex,
"Classes should use dash-form.")
re.VERBOSE)
# $i18n{...} messes with highlighting. Special path for this.
if "$i18n{" in line:
match = re.search(class_regex, re.sub("\$i18n{[^}]+}", "", line))
return " line %d: %s" % (line_number, msg) if match else ""
return regex_check.RegexCheck(re, line_number, line, class_regex, msg)
def DoNotCloseSingleTagsCheck(self, line_number, line):
regex = r"(/>)"
......
......@@ -52,6 +52,7 @@ class HtmlCheckerTest(SuperMoxTestBase):
' class="abc" ',
'class="foo-bar"',
'<div class="foo-bar" id="classBar"',
'<div class="foo $i18n{barBazQux}" id="classBar"',
]
for line in lines:
self.ShouldPassCheck(line, self.checker.ClassesUseDashFormCheck)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment