Index: chrome/browser/web_dev_style/css_checker.py |
diff --git a/chrome/browser/web_dev_style/css_checker.py b/chrome/browser/web_dev_style/css_checker.py |
index 77f610f4db804a7f0c0e52f8400ad54333d9de5d..ef40802a103808add79abb298612b0e80eaf48ad 100644 |
--- a/chrome/browser/web_dev_style/css_checker.py |
+++ b/chrome/browser/web_dev_style/css_checker.py |
@@ -29,42 +29,43 @@ class CSSChecker(object): |
return s[0] == s[1] == s[2] if len(s) == 3 else s[0:2] == s[2:4] == s[4:6] |
def _remove_all(s): |
- s = _remove_grit(s) |
+ s = _remove_grit(s) # Must be done first. |
dschuyler
2016/09/22 18:58:44
Thanks for this comment!
Dan Beam
2016/09/22 19:45:41
Acknowledged.
|
s = _remove_ats(s) |
s = _remove_comments(s) |
+ s = _remove_mixins_and_valid_vars(s) |
s = _remove_template_expressions(s) |
- s = _remove_mixins(s) |
return s |
def _extract_inline_style(s): |
return '\n'.join(re.findall(r'<style\b[^>]*>([^<]*)<\/style>', s)) |
def _remove_ats(s): |
- at_reg = re.compile(r""" |
+ return re.sub(r""" |
@(?!apply)(?!\d+x\b) # @at-keyword, not (apply|2x) |
\w+[^'"]*?{ # selector junk { |
(.*{.*?})+ # inner { curly } blocks, rules, and selector |
.*?} # stuff up to the first end curly } |
- """, |
- re.DOTALL | re.VERBOSE) |
- return at_reg.sub('\\1', s) |
+ """, r'\1', s, flags=re.DOTALL | re.VERBOSE) |
def _remove_comments(s): |
- return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) |
- |
- def _remove_mixins(s): |
- return re.sub(re.compile(r'--[\d\w-]+: {.*?};', re.DOTALL), '', s) |
- |
- def _remove_template_expressions(s): |
- return re.sub(re.compile(r'\$i18n(Raw)?{[^}]*}', re.DOTALL), '', s) |
+ return re.sub(r'/\*.*?\*/', '', s, flags=re.DOTALL) |
def _remove_grit(s): |
- grit_reg = re.compile(r""" |
+ return re.sub(r""" |
<if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if> |
<include[^>]+> # <include> |
- """, |
- re.DOTALL | re.VERBOSE) |
- return re.sub(grit_reg, '', s) |
+ """, '', s, flags=re.DOTALL | re.VERBOSE) |
+ |
+ mixin_shim_reg = r'[\w-]+_-_[\w-]+' |
+ |
+ def _remove_mixins_and_valid_vars(s): |
+ not_shim = r'--(?!' + mixin_shim_reg + r')' |
+ name = r'[\w-]+:\s*' |
+ mixin_or_value = r'({.*?}|[^;}]+);?\s*' |
+ return re.sub(not_shim + name + mixin_or_value, '', s, flags=re.DOTALL) |
dschuyler
2016/09/22 18:58:44
optional: not_shim is actually '--'
plus the not
Dan Beam
2016/09/22 19:45:41
Done.
|
+ |
+ def _remove_template_expressions(s): |
+ return re.sub(r'\$i18n(Raw)?{[^}]*}', '', s, flags=re.DOTALL) |
def _rgb_from_hex(s): |
if len(s) == 3: |
@@ -170,7 +171,7 @@ class CSSChecker(object): |
return re.search(r'\(\s*\s*data:', line) |
def no_mixin_shims(line): |
- return re.search('\-\-[\w\-]+_\-_[\w\-]+\s*:', line) |
+ return re.search(r'--' + mixin_shim_reg + r'\s*:', line) |
def no_quotes_in_url(line): |
return re.search('url\s*\(\s*["\']', line, re.IGNORECASE) |