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

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: Review comments 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
« no previous file with comments | « no previous file | chrome/browser/web_dev_style/css_checker_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6b6a923ec0720eb58387cb94811bf285a4138236 100644
--- a/chrome/browser/web_dev_style/css_checker.py
+++ b/chrome/browser/web_dev_style/css_checker.py
@@ -36,6 +36,9 @@ class CSSChecker(object):
s = _remove_mixins(s)
return s
+ def _extract_inline_style(s):
+ return '\n'.join(re.findall(r'<style>([^<]*)<\/style>', s))
+
def _remove_ats(s):
at_reg = re.compile(r"""
@(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x
@@ -375,13 +378,20 @@ 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)
+
+ 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698