OLD | NEW |
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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 def milliseconds_for_small_times(line): | 162 def milliseconds_for_small_times(line): |
163 return small_seconds_reg.search(line) | 163 return small_seconds_reg.search(line) |
164 | 164 |
165 def suggest_ms_from_s(line): | 165 def suggest_ms_from_s(line): |
166 ms = int(float(small_seconds_reg.search(line).group(1)) * 1000) | 166 ms = int(float(small_seconds_reg.search(line).group(1)) * 1000) |
167 return ' (replace with %dms)' % ms | 167 return ' (replace with %dms)' % ms |
168 | 168 |
169 def no_data_uris_in_source_files(line): | 169 def no_data_uris_in_source_files(line): |
170 return re.search(r'\(\s*\s*data:', line) | 170 return re.search(r'\(\s*\s*data:', line) |
171 | 171 |
| 172 def no_mixin_shims(line): |
| 173 return re.search('\-\-[\w\-]+_\-_[\w\-]+\s*:', line) |
| 174 |
172 def no_quotes_in_url(line): | 175 def no_quotes_in_url(line): |
173 return re.search('url\s*\(\s*["\']', line, re.IGNORECASE) | 176 return re.search('url\s*\(\s*["\']', line, re.IGNORECASE) |
174 | 177 |
175 def one_rule_per_line(line): | 178 def one_rule_per_line(line): |
176 one_rule_reg = re.compile(r""" | 179 one_rule_reg = re.compile(r""" |
177 [\w-](?<!data): # a rule: but no data URIs | 180 [\w-](?<!data): # a rule: but no data URIs |
178 (?!//)[^;]+; # value; ignoring colons in protocols:// and }; | 181 (?!//)[^;]+; # value; ignoring colons in protocols:// and }; |
179 \s*[^ }]\s* # any non-space after the end colon | 182 \s*[^ }]\s* # any non-space after the end colon |
180 """, | 183 """, |
181 re.VERBOSE) | 184 re.VERBOSE) |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 'test': hex_could_be_shorter, | 342 'test': hex_could_be_shorter, |
340 'after': suggest_short_hex, | 343 'after': suggest_short_hex, |
341 }, | 344 }, |
342 { 'desc': 'Use milliseconds for time measurements under 1 second.', | 345 { 'desc': 'Use milliseconds for time measurements under 1 second.', |
343 'test': milliseconds_for_small_times, | 346 'test': milliseconds_for_small_times, |
344 'after': suggest_ms_from_s, | 347 'after': suggest_ms_from_s, |
345 }, | 348 }, |
346 { 'desc': "Don't use data URIs in source files. Use grit instead.", | 349 { 'desc': "Don't use data URIs in source files. Use grit instead.", |
347 'test': no_data_uris_in_source_files, | 350 'test': no_data_uris_in_source_files, |
348 }, | 351 }, |
| 352 { 'desc': "Don't override custom properties created by Polymer's mixin " |
| 353 "shim. Set mixins or documented custom properties directly.", |
| 354 'test': no_mixin_shims, |
| 355 }, |
349 { 'desc': "Don't use quotes in url().", | 356 { 'desc': "Don't use quotes in url().", |
350 'test': no_quotes_in_url, | 357 'test': no_quotes_in_url, |
351 }, | 358 }, |
352 { 'desc': 'One rule per line (what not to do: color: red; margin: 0;).', | 359 { 'desc': 'One rule per line (what not to do: color: red; margin: 0;).', |
353 'test': one_rule_per_line, | 360 'test': one_rule_per_line, |
354 }, | 361 }, |
355 { 'desc': 'One selector per line (what not to do: a, b {}).', | 362 { 'desc': 'One selector per line (what not to do: a, b {}).', |
356 'test': one_selector_per_line, | 363 'test': one_selector_per_line, |
357 'multiline': True, | 364 'multiline': True, |
358 }, | 365 }, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 error += check['after'](line) | 421 error += check['after'](line) |
415 check_errors.append(error) | 422 check_errors.append(error) |
416 if len(check_errors) > 0: | 423 if len(check_errors) > 0: |
417 file_errors.append('- %s\n%s' % | 424 file_errors.append('- %s\n%s' % |
418 (check['desc'], '\n'.join(check_errors))) | 425 (check['desc'], '\n'.join(check_errors))) |
419 if file_errors: | 426 if file_errors: |
420 results.append(self.output_api.PresubmitPromptWarning( | 427 results.append(self.output_api.PresubmitPromptWarning( |
421 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) | 428 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
422 | 429 |
423 return results | 430 return results |
OLD | NEW |