Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 gcl/git cl, and see | 8 for more details about the presubmit API built into gcl/git cl, 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 # Intentionally dumbed down version of CSS 2.1 grammar for class without | 58 # Intentionally dumbed down version of CSS 2.1 grammar for class without |
| 59 # non-ASCII, escape chars, or whitespace. | 59 # non-ASCII, escape chars, or whitespace. |
| 60 m = re.search(r'\.(-?[_a-zA-Z0-9-]+).*[,{]\s*$', line) | 60 m = re.search(r'\.(-?[_a-zA-Z0-9-]+).*[,{]\s*$', line) |
| 61 return (m and (m.group(1).lower() != m.group(1) or | 61 return (m and (m.group(1).lower() != m.group(1) or |
| 62 m.group(1).find('_') >= 0)) | 62 m.group(1).find('_') >= 0)) |
| 63 | 63 |
| 64 def close_brace_on_new_line(line): | 64 def close_brace_on_new_line(line): |
| 65 return (line.find('}') >= 0 and re.search(r'[^ }]', line)) | 65 return (line.find('}') >= 0 and re.search(r'[^ }]', line)) |
| 66 | 66 |
| 67 def colons_have_space_after(line): | 67 def colons_have_space_after(line): |
| 68 return re.search(r':(?!\/\/)\S(?!.*[{,]\s*$)', line) | 68 return re.search(r':(?!\/\/)\S[^;]+;\s*', line) |
| 69 | 69 |
| 70 def favor_single_quotes(line): | 70 def favor_single_quotes(line): |
| 71 return line.find('"') >= 0 | 71 return line.find('"') >= 0 |
| 72 | 72 |
| 73 # Shared between hex_could_be_shorter and rgb_if_not_gray. | 73 # Shared between hex_could_be_shorter and rgb_if_not_gray. |
| 74 hex_reg = (r'#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})(?=[^_a-zA-Z0-9-]|$)' | 74 hex_reg = (r'#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})(?=[^_a-zA-Z0-9-]|$)' |
| 75 r'(?!.*(?:{.*|,\s*)$)') | 75 r'(?!.*(?:{.*|,\s*)$)') |
| 76 def hex_could_be_shorter(line): | 76 def hex_could_be_shorter(line): |
| 77 m = re.search(hex_reg, line) | 77 m = re.search(hex_reg, line) |
| 78 return (m and _collapseable_hex(m.group(1))) | 78 return (m and _collapseable_hex(m.group(1))) |
| 79 | 79 |
| 80 small_seconds = r'(?:^|[^_a-zA-Z0-9-])(0?\.[0-9]+)s(?!-?[_a-zA-Z0-9-])' | 80 small_seconds = r'(?:^|[^_a-zA-Z0-9-])(0?\.[0-9]+)s(?!-?[_a-zA-Z0-9-])' |
| 81 def milliseconds_for_small_times(line): | 81 def milliseconds_for_small_times(line): |
| 82 return re.search(small_seconds, line) | 82 return re.search(small_seconds, line) |
| 83 | 83 |
| 84 def one_rule_per_line(line): | 84 def one_rule_per_line(line): |
| 85 return re.search('(.*:(?!\/\/)){2,}(?!.*[,{]\s*$)', line) | 85 return re.search('[_a-zA-Z0-9-]:(?!\/\/)[^;]+;\s*[^ }]\s*', line) |
|
Tyler Breisacher (Chromium)
2012/03/21 20:30:03
You don't have to escape the slashes. So (?!\/\/)
Dan Beam
2012/03/21 20:47:29
this is ignoring the : in protocols as in:
backg
| |
| 86 | 86 |
| 87 any_reg = re.compile(r':(?:-webkit-)?any\(.*?\)', re.DOTALL) | 87 any_reg = re.compile(r':(?:-webkit-)?any\(.*?\)', re.DOTALL) |
| 88 multi_sels = re.compile(r'(?:}[\n\s]*)?([^,]+,(?=[^{}]+?{).*[,{])\s*$', | 88 multi_sels = re.compile(r'(?:}[\n\s]*)?([^,]+,(?=[^{}]+?{).*[,{])\s*$', |
| 89 re.MULTILINE) | 89 re.MULTILINE) |
| 90 def one_selector_per_line(contents): | 90 def one_selector_per_line(contents): |
| 91 errors = [] | 91 errors = [] |
| 92 for b in re.finditer(multi_sels, re.sub(any_reg, '', contents)): | 92 for b in re.finditer(multi_sels, re.sub(any_reg, '', contents)): |
| 93 errors.append(' ' + b.group(1).strip()) | 93 errors.append(' ' + b.group(1).strip()) |
| 94 return errors | 94 return errors |
| 95 | 95 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) | 205 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
| 206 | 206 |
| 207 if results: | 207 if results: |
| 208 # Add your name if you're here often mucking around in the code. | 208 # Add your name if you're here often mucking around in the code. |
| 209 authors = ['dbeam@chromium.org'] | 209 authors = ['dbeam@chromium.org'] |
| 210 results.append(self.output_api.PresubmitNotifyResult( | 210 results.append(self.output_api.PresubmitNotifyResult( |
| 211 'Was the CSS checker useful? Send feedback or hate mail to %s.' % | 211 'Was the CSS checker useful? Send feedback or hate mail to %s.' % |
| 212 ', '.join(authors))) | 212 ', '.join(authors))) |
| 213 | 213 |
| 214 return results | 214 return results |
| OLD | NEW |