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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 def suggest_rgb_from_hex(line): | 117 def suggest_rgb_from_hex(line): |
| 118 suggestions = ['rgb(%d, %d, %d)' % _rgb_from_hex(h.group(1)) | 118 suggestions = ['rgb(%d, %d, %d)' % _rgb_from_hex(h.group(1)) |
| 119 for h in re.finditer(hex_reg, line)] | 119 for h in re.finditer(hex_reg, line)] |
| 120 return ' (replace with %s)' % ', '.join(suggestions) | 120 return ' (replace with %s)' % ', '.join(suggestions) |
| 121 | 121 |
| 122 def suggest_short_hex(line): | 122 def suggest_short_hex(line): |
| 123 h = re.search(hex_reg, line).group(1) | 123 h = re.search(hex_reg, line).group(1) |
| 124 return ' (replace with #%s)' % (h[0] + h[2] + h[4]) | 124 return ' (replace with #%s)' % (h[0] + h[2] + h[4]) |
| 125 | 125 |
| 126 hsl = r'hsl\([^\)]*(?:[, ]|(?<=\())(?:0?\.?)?0%' | 126 hsl = r'hsl\([^\)]*(?:[, ]|(?<=\())(?:0?\.?)?0%' |
| 127 zeros = (r'(?:^|\D)' | 127 zeros = (r'^.*(?:^|\D)' |
|
Yoyo Zhou
2012/04/20 01:31:40
It seems like for the example "state0." in the tes
| |
| 128 r'(?:\.0|0(?:\.0?|px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz))' | 128 r'(?:\.0|0(?:\.0?|px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz))' |
| 129 r'(?:\D|$)(?!\s*\{)') | 129 r'(?:\D|$)(?=[^{}]+?}).*$') |
|
Yoyo Zhou
2012/04/20 01:31:40
The last } is literal, right? It's confusing witho
| |
| 130 def zero_length_values(line): | 130 def zero_length_values(contents): |
| 131 return (re.search(zeros, line) and not re.search(hsl, line)) | 131 errors = [] |
| 132 for z in re.finditer(re.compile(zeros, re.MULTILINE), contents): | |
| 133 first_line = z.group(0).strip().splitlines()[0] | |
| 134 if not re.search(hsl, first_line): | |
| 135 errors.append(' ' + first_line) | |
| 136 return errors | |
| 132 | 137 |
| 133 added_or_modified_files_checks = [ | 138 added_or_modified_files_checks = [ |
| 134 { 'desc': 'Alphabetize properties and list vendor specific (i.e. ' | 139 { 'desc': 'Alphabetize properties and list vendor specific (i.e. ' |
| 135 '-webkit) above standard.', | 140 '-webkit) above standard.', |
| 136 'test': alphabetize_props, | 141 'test': alphabetize_props, |
| 137 'multiline': True, | 142 'multiline': True, |
| 138 }, | 143 }, |
| 139 { 'desc': 'Start braces ({) end a selector, have a space before them ' | 144 { 'desc': 'Start braces ({) end a selector, have a space before them ' |
| 140 'and no rules after.', | 145 'and no rules after.', |
| 141 'test': braces_have_space_before_and_nothing_after, | 146 'test': braces_have_space_before_and_nothing_after, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 171 'test': one_selector_per_line, | 176 'test': one_selector_per_line, |
| 172 'multiline': True, | 177 'multiline': True, |
| 173 }, | 178 }, |
| 174 { 'desc': 'Use rgb() over #hex when not a shade of gray (like #333).', | 179 { 'desc': 'Use rgb() over #hex when not a shade of gray (like #333).', |
| 175 'test': rgb_if_not_gray, | 180 'test': rgb_if_not_gray, |
| 176 'after': suggest_rgb_from_hex, | 181 'after': suggest_rgb_from_hex, |
| 177 }, | 182 }, |
| 178 { 'desc': 'Make all zero length terms (i.e. 0px) 0 unless inside of ' | 183 { 'desc': 'Make all zero length terms (i.e. 0px) 0 unless inside of ' |
| 179 'hsl() or part of @keyframe.', | 184 'hsl() or part of @keyframe.', |
| 180 'test': zero_length_values, | 185 'test': zero_length_values, |
| 186 'multiline': True, | |
| 181 }, | 187 }, |
| 182 ] | 188 ] |
| 183 | 189 |
| 184 results = [] | 190 results = [] |
| 185 affected_files = self.input_api.AffectedFiles(include_deletes=False, | 191 affected_files = self.input_api.AffectedFiles(include_deletes=False, |
| 186 file_filter=self.file_filter) | 192 file_filter=self.file_filter) |
| 187 files = [] | 193 files = [] |
| 188 for f in affected_files: | 194 for f in affected_files: |
| 189 # Remove all /*comments*/, @at-keywords, and grit <if|include> tags; we're | 195 # Remove all /*comments*/, @at-keywords, and grit <if|include> tags; we're |
| 190 # not using a real parser. TODO(dbeam): Check alpha in <if> blocks. | 196 # not using a real parser. TODO(dbeam): Check alpha in <if> blocks. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) | 228 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
| 223 | 229 |
| 224 if results: | 230 if results: |
| 225 # Add your name if you're here often mucking around in the code. | 231 # Add your name if you're here often mucking around in the code. |
| 226 authors = ['dbeam@chromium.org'] | 232 authors = ['dbeam@chromium.org'] |
| 227 results.append(self.output_api.PresubmitNotifyResult( | 233 results.append(self.output_api.PresubmitNotifyResult( |
| 228 'Was the CSS checker useful? Send feedback or hate mail to %s.' % | 234 'Was the CSS checker useful? Send feedback or hate mail to %s.' % |
| 229 ', '.join(authors))) | 235 ', '.join(authors))) |
| 230 | 236 |
| 231 return results | 237 return results |
| OLD | NEW |