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

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: more review stuff 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
« no previous file with comments | « no previous file | chrome/browser/web_dev_style/css_checker_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11 matching lines...) Expand all
22 # We use this a lot, so make a nick name variable. 22 # We use this a lot, so make a nick name variable.
23 re = self.input_api.re 23 re = self.input_api.re
24 24
25 def _collapseable_hex(s): 25 def _collapseable_hex(s):
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) # Must be done first.
dschuyler 2016/09/22 18:58:44 Thanks for this comment!
Dan Beam 2016/09/22 19:45:41 Acknowledged.
33 s = _remove_ats(s) 33 s = _remove_ats(s)
34 s = _remove_comments(s) 34 s = _remove_comments(s)
35 s = _remove_mixins_and_valid_vars(s)
35 s = _remove_template_expressions(s) 36 s = _remove_template_expressions(s)
36 s = _remove_mixins(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 return re.sub(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 """, r'\1', s, flags=re.DOTALL | re.VERBOSE)
49 re.DOTALL | re.VERBOSE)
50 return at_reg.sub('\\1', s)
51 49
52 def _remove_comments(s): 50 def _remove_comments(s):
53 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) 51 return re.sub(r'/\*.*?\*/', '', s, flags=re.DOTALL)
54 52
55 def _remove_mixins(s): 53 def _remove_grit(s):
56 return re.sub(re.compile(r'--[\d\w-]+: {.*?};', re.DOTALL), '', s) 54 return re.sub(r"""
55 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if>
56 <include[^>]+> # <include>
57 """, '', s, flags=re.DOTALL | re.VERBOSE)
58
59 mixin_shim_reg = r'[\w-]+_-_[\w-]+'
60
61 def _remove_mixins_and_valid_vars(s):
62 not_shim = r'--(?!' + mixin_shim_reg + r')'
63 name = r'[\w-]+:\s*'
64 mixin_or_value = r'({.*?}|[^;}]+);?\s*'
65 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.
57 66
58 def _remove_template_expressions(s): 67 def _remove_template_expressions(s):
59 return re.sub(re.compile(r'\$i18n(Raw)?{[^}]*}', re.DOTALL), '', s) 68 return re.sub(r'\$i18n(Raw)?{[^}]*}', '', s, flags=re.DOTALL)
60
61 def _remove_grit(s):
62 grit_reg = re.compile(r"""
63 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if>
64 <include[^>]+> # <include>
65 """,
66 re.DOTALL | re.VERBOSE)
67 return re.sub(grit_reg, '', s)
68 69
69 def _rgb_from_hex(s): 70 def _rgb_from_hex(s):
70 if len(s) == 3: 71 if len(s) == 3:
71 r, g, b = s[0] + s[0], s[1] + s[1], s[2] + s[2] 72 r, g, b = s[0] + s[0], s[1] + s[1], s[2] + s[2]
72 else: 73 else:
73 r, g, b = s[0:2], s[2:4], s[4:6] 74 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) 75 return int(r, base=16), int(g, base=16), int(b, base=16)
75 76
76 def _strip_prefix(s): 77 def _strip_prefix(s):
77 return re.sub(r'^-(?:o|ms|moz|khtml|webkit)-', '', s) 78 return re.sub(r'^-(?:o|ms|moz|khtml|webkit)-', '', s)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 return small_seconds_reg.search(line) 164 return small_seconds_reg.search(line)
164 165
165 def suggest_ms_from_s(line): 166 def suggest_ms_from_s(line):
166 ms = int(float(small_seconds_reg.search(line).group(1)) * 1000) 167 ms = int(float(small_seconds_reg.search(line).group(1)) * 1000)
167 return ' (replace with %dms)' % ms 168 return ' (replace with %dms)' % ms
168 169
169 def no_data_uris_in_source_files(line): 170 def no_data_uris_in_source_files(line):
170 return re.search(r'\(\s*\s*data:', line) 171 return re.search(r'\(\s*\s*data:', line)
171 172
172 def no_mixin_shims(line): 173 def no_mixin_shims(line):
173 return re.search('\-\-[\w\-]+_\-_[\w\-]+\s*:', line) 174 return re.search(r'--' + mixin_shim_reg + r'\s*:', line)
174 175
175 def no_quotes_in_url(line): 176 def no_quotes_in_url(line):
176 return re.search('url\s*\(\s*["\']', line, re.IGNORECASE) 177 return re.search('url\s*\(\s*["\']', line, re.IGNORECASE)
177 178
178 def one_rule_per_line(line): 179 def one_rule_per_line(line):
179 one_rule_reg = re.compile(r""" 180 one_rule_reg = re.compile(r"""
180 [\w-](?<!data): # a rule: but no data URIs 181 [\w-](?<!data): # a rule: but no data URIs
181 (?!//)[^;]+; # value; ignoring colons in protocols:// and }; 182 (?!//)[^;]+; # value; ignoring colons in protocols:// and };
182 \s*[^ }]\s* # any non-space after the end colon 183 \s*[^ }]\s* # any non-space after the end colon
183 """, 184 """,
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 error += check['after'](line) 422 error += check['after'](line)
422 check_errors.append(error) 423 check_errors.append(error)
423 if len(check_errors) > 0: 424 if len(check_errors) > 0:
424 file_errors.append('- %s\n%s' % 425 file_errors.append('- %s\n%s' %
425 (check['desc'], '\n'.join(check_errors))) 426 (check['desc'], '\n'.join(check_errors)))
426 if file_errors: 427 if file_errors:
427 results.append(self.output_api.PresubmitPromptWarning( 428 results.append(self.output_api.PresubmitPromptWarning(
428 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) 429 '%s:\n%s' % (f[0], '\n\n'.join(file_errors))))
429 430
430 return results 431 return results
OLDNEW
« 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