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

Side by Side Diff: chrome/browser/web_dev_style/css_checker.py

Issue 2345703004: web_dev_style: ignore --css-vars from alphabetical ordering requirement (Closed)
Patch Set: combine mixin+var logic Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 # Copyright 2012 The Chromium Authors. All rights reserved. 1 # Copyright 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Presubmit script for Chromium WebUI resources. 5 """Presubmit script for Chromium WebUI resources.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools, and see 8 for more details about the presubmit API built into depot_tools, and see
9 http://www.chromium.org/developers/web-development-style-guide for the rules 9 http://www.chromium.org/developers/web-development-style-guide for the rules
10 we're checking against here. 10 we're checking against here.
(...skipping 15 matching lines...) Expand all
26 return (len(s) == 6 and s[0] == s[1] and s[2] == s[3] and s[4] == s[5]) 26 return (len(s) == 6 and s[0] == s[1] and s[2] == s[3] and s[4] == s[5])
27 27
28 def _is_gray(s): 28 def _is_gray(s):
29 return s[0] == s[1] == s[2] if len(s) == 3 else s[0:2] == s[2:4] == s[4:6] 29 return s[0] == s[1] == s[2] if len(s) == 3 else s[0:2] == s[2:4] == s[4:6]
30 30
31 def _remove_all(s): 31 def _remove_all(s):
32 s = _remove_grit(s) 32 s = _remove_grit(s)
33 s = _remove_ats(s) 33 s = _remove_ats(s)
34 s = _remove_comments(s) 34 s = _remove_comments(s)
35 s = _remove_template_expressions(s) 35 s = _remove_template_expressions(s)
36 s = _remove_mixins(s) 36 s = _remove_valid_vars(s)
37 return s 37 return s
38 38
39 def _extract_inline_style(s): 39 def _extract_inline_style(s):
40 return '\n'.join(re.findall(r'<style\b[^>]*>([^<]*)<\/style>', s)) 40 return '\n'.join(re.findall(r'<style\b[^>]*>([^<]*)<\/style>', s))
41 41
42 def _remove_ats(s): 42 def _remove_ats(s):
43 at_reg = re.compile(r""" 43 at_reg = re.compile(r"""
44 @(?!apply)(?!\d+x\b) # @at-keyword, not (apply|2x) 44 @(?!apply)(?!\d+x\b) # @at-keyword, not (apply|2x)
45 \w+[^'"]*?{ # selector junk { 45 \w+[^'"]*?{ # selector junk {
46 (.*{.*?})+ # inner { curly } blocks, rules, and selector 46 (.*{.*?})+ # inner { curly } blocks, rules, and selector
47 .*?} # stuff up to the first end curly } 47 .*?} # stuff up to the first end curly }
48 """, 48 """,
49 re.DOTALL | re.VERBOSE) 49 re.DOTALL | re.VERBOSE)
50 return at_reg.sub('\\1', s) 50 return at_reg.sub('\\1', s)
51 51
52 def _remove_comments(s): 52 def _remove_comments(s):
53 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) 53 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s)
54 54
55 def _remove_mixins(s):
56 return re.sub(re.compile(r'--[\d\w-]+: {.*?};', re.DOTALL), '', s)
dschuyler 2016/09/19 21:23:28 With this no longer being done, it looks like some
57
58 def _remove_template_expressions(s):
59 return re.sub(re.compile(r'\$i18n(Raw)?{[^}]*}', re.DOTALL), '', s)
60
61 def _remove_grit(s): 55 def _remove_grit(s):
62 grit_reg = re.compile(r""" 56 grit_reg = re.compile(r"""
63 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if> 57 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if>
64 <include[^>]+> # <include> 58 <include[^>]+> # <include>
65 """, 59 """,
66 re.DOTALL | re.VERBOSE) 60 re.DOTALL | re.VERBOSE)
67 return re.sub(grit_reg, '', s) 61 return re.sub(grit_reg, '', s)
68 62
63 def _remove_template_expressions(s):
64 return re.sub(re.compile(r'\$i18n(Raw)?{[^}]*}', re.DOTALL), '', s)
65
66 mixin_shim_reg = '[\w\d-]+_-_[\w\d-]+'
67
68 def _remove_valid_vars(s):
69 valid_var_reg = '--(?!' + mixin_shim_reg + ')[\d\w-]+\s*:\s*[^;]+?;'
70 return re.sub(re.compile(valid_var_reg, re.DOTALL), '', s)
dschuyler 2016/09/19 21:23:28 About the regex changes: - having \d and \w in the
Dan Beam 2016/09/22 02:13:26 Done.
71
69 def _rgb_from_hex(s): 72 def _rgb_from_hex(s):
70 if len(s) == 3: 73 if len(s) == 3:
71 r, g, b = s[0] + s[0], s[1] + s[1], s[2] + s[2] 74 r, g, b = s[0] + s[0], s[1] + s[1], s[2] + s[2]
72 else: 75 else:
73 r, g, b = s[0:2], s[2:4], s[4:6] 76 r, g, b = s[0:2], s[2:4], s[4:6]
74 return int(r, base=16), int(g, base=16), int(b, base=16) 77 return int(r, base=16), int(g, base=16), int(b, base=16)
75 78
76 def _strip_prefix(s): 79 def _strip_prefix(s):
77 return re.sub(r'^-(?:o|ms|moz|khtml|webkit)-', '', s) 80 return re.sub(r'^-(?:o|ms|moz|khtml|webkit)-', '', s)
78 81
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 return small_seconds_reg.search(line) 166 return small_seconds_reg.search(line)
164 167
165 def suggest_ms_from_s(line): 168 def suggest_ms_from_s(line):
166 ms = int(float(small_seconds_reg.search(line).group(1)) * 1000) 169 ms = int(float(small_seconds_reg.search(line).group(1)) * 1000)
167 return ' (replace with %dms)' % ms 170 return ' (replace with %dms)' % ms
168 171
169 def no_data_uris_in_source_files(line): 172 def no_data_uris_in_source_files(line):
170 return re.search(r'\(\s*\s*data:', line) 173 return re.search(r'\(\s*\s*data:', line)
171 174
172 def no_mixin_shims(line): 175 def no_mixin_shims(line):
173 return re.search('\-\-[\w\-]+_\-_[\w\-]+\s*:', line) 176 return re.search('--' + mixin_shim_reg + '\s*:', line)
174 177
175 def no_quotes_in_url(line): 178 def no_quotes_in_url(line):
176 return re.search('url\s*\(\s*["\']', line, re.IGNORECASE) 179 return re.search('url\s*\(\s*["\']', line, re.IGNORECASE)
177 180
178 def one_rule_per_line(line): 181 def one_rule_per_line(line):
179 one_rule_reg = re.compile(r""" 182 one_rule_reg = re.compile(r"""
180 [\w-](?<!data): # a rule: but no data URIs 183 [\w-](?<!data): # a rule: but no data URIs
181 (?!//)[^;]+; # value; ignoring colons in protocols:// and }; 184 (?!//)[^;]+; # value; ignoring colons in protocols:// and };
182 \s*[^ }]\s* # any non-space after the end colon 185 \s*[^ }]\s* # any non-space after the end colon
183 """, 186 """,
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 error += check['after'](line) 424 error += check['after'](line)
422 check_errors.append(error) 425 check_errors.append(error)
423 if len(check_errors) > 0: 426 if len(check_errors) > 0:
424 file_errors.append('- %s\n%s' % 427 file_errors.append('- %s\n%s' %
425 (check['desc'], '\n'.join(check_errors))) 428 (check['desc'], '\n'.join(check_errors)))
426 if file_errors: 429 if file_errors:
427 results.append(self.output_api.PresubmitPromptWarning( 430 results.append(self.output_api.PresubmitPromptWarning(
428 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) 431 '%s:\n%s' % (f[0], '\n\n'.join(file_errors))))
429 432
430 return results 433 return results
OLDNEW
« 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