Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: chrome/browser/web_dev_style/css_checker.py

Issue 1639863004: Add support for inline CSS in HTML files to CSS Presubmit checker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 7d03a60feb8bd7b846cc94ed52edaa50beb03e2a..67f0ffca236fc1dcd4c750d8bede2f5b56d62fe3 100644
--- a/chrome/browser/web_dev_style/css_checker.py
+++ b/chrome/browser/web_dev_style/css_checker.py
@@ -36,6 +36,11 @@ class CSSChecker(object):
s = _remove_mixins(s)
return s
+ def _extract_inline_style(s):
+ style_reg = re.compile(r"""<style>([^<]*)<\/style>""")
+ styles = style_reg.findall(s)
+ return '\n'.join(styles)
Dan Beam 2016/01/27 02:50:45 nit: to improve your code golf swing return '\n
tsergeant 2016/01/27 03:12:14 Done, one-upping by getting rid of the compile.
+
def _remove_ats(s):
at_reg = re.compile(r"""
@(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x
@@ -375,13 +380,19 @@ class CSSChecker(object):
file_filter=self.file_filter)
files = []
for f in affected_files:
- # Remove all /*comments*/, @at-keywords, and grit <if|include> tags; we're
- # not using a real parser. TODO(dbeam): Check alpha in <if> blocks.
- file_contents = _remove_all('\n'.join(f.NewContents()))
- files.append((f.LocalPath(), file_contents))
-
- # Only look at CSS files for now.
- for f in filter(lambda f: f[0].endswith('.css'), files):
+ file_contents = '\n'.join(f.NewContents())
+ path = f.LocalPath()
+ # Handle CSS files and HTML files with inline styles.
+ if path.endswith('.html'):
+ file_contents = _extract_inline_style(file_contents)
Dan Beam 2016/01/27 02:50:45 nit: \n
tsergeant 2016/01/27 03:12:14 Done.
+ if path.endswith('.html') or path.endswith('.css'):
+ # Remove all /*comments*/, @at-keywords, and grit <if|include> tags;
+ # we're not using a real parser. TODO(dbeam): Check alpha in <if>
+ # blocks.
+ file_contents = _remove_all(file_contents)
+ files.append((path, file_contents))
+
+ for f in files:
file_errors = []
for check in added_or_modified_files_checks:
# If the check is multiline, it receieves the whole file and gives us
« no previous file with comments | « no previous file | chrome/browser/web_dev_style/css_checker_test.py » ('j') | chrome/browser/web_dev_style/css_checker_test.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698