| 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..d55bcca6be62b95d7aeb1195b3dc02c3f4f2a056 100644
|
| --- a/chrome/browser/web_dev_style/css_checker.py
|
| +++ b/chrome/browser/web_dev_style/css_checker.py
|
| @@ -29,42 +29,42 @@ 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.
|
| 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):
|
| + valid_vars = r'--(?!' + mixin_shim_reg + r')[\w-]+:\s*'
|
| + mixin_or_value = r'({.*?}|[^;}]+);?\s*'
|
| + return re.sub(valid_vars + mixin_or_value, '', s, flags=re.DOTALL)
|
| +
|
| + 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 +170,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)
|
|
|