| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 # Intentionally dumbed down version of CSS 2.1 grammar for class without | 65 # Intentionally dumbed down version of CSS 2.1 grammar for class without |
| 66 # non-ASCII, escape chars, or whitespace. | 66 # non-ASCII, escape chars, or whitespace. |
| 67 m = re.search(r'\.(-?[_a-zA-Z0-9-]+).*[,{]\s*$', line) | 67 m = re.search(r'\.(-?[_a-zA-Z0-9-]+).*[,{]\s*$', line) |
| 68 return (m and (m.group(1).lower() != m.group(1) or | 68 return (m and (m.group(1).lower() != m.group(1) or |
| 69 m.group(1).find('_') >= 0)) | 69 m.group(1).find('_') >= 0)) |
| 70 | 70 |
| 71 def close_brace_on_new_line(line): | 71 def close_brace_on_new_line(line): |
| 72 return (line.find('}') >= 0 and re.search(r'[^ }]', line)) | 72 return (line.find('}') >= 0 and re.search(r'[^ }]', line)) |
| 73 | 73 |
| 74 def colons_have_space_after(line): | 74 def colons_have_space_after(line): |
| 75 return re.search(r':(?!\/\/)\S(?!.*[{,]\s*$)', line) | 75 return re.search(r':(?!//)\S[^;]+;\s*', line) |
| 76 | 76 |
| 77 def favor_single_quotes(line): | 77 def favor_single_quotes(line): |
| 78 return line.find('"') >= 0 | 78 return line.find('"') >= 0 |
| 79 | 79 |
| 80 # Shared between hex_could_be_shorter and rgb_if_not_gray. | 80 # Shared between hex_could_be_shorter and rgb_if_not_gray. |
| 81 hex_reg = (r'#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})(?=[^_a-zA-Z0-9-]|$)' | 81 hex_reg = (r'#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})(?=[^_a-zA-Z0-9-]|$)' |
| 82 r'(?!.*(?:{.*|,\s*)$)') | 82 r'(?!.*(?:{.*|,\s*)$)') |
| 83 def hex_could_be_shorter(line): | 83 def hex_could_be_shorter(line): |
| 84 m = re.search(hex_reg, line) | 84 m = re.search(hex_reg, line) |
| 85 return (m and _collapseable_hex(m.group(1))) | 85 return (m and _collapseable_hex(m.group(1))) |
| 86 | 86 |
| 87 small_seconds = r'(?:^|[^_a-zA-Z0-9-])(0?\.[0-9]+)s(?!-?[_a-zA-Z0-9-])' | 87 small_seconds = r'(?:^|[^_a-zA-Z0-9-])(0?\.[0-9]+)s(?!-?[_a-zA-Z0-9-])' |
| 88 def milliseconds_for_small_times(line): | 88 def milliseconds_for_small_times(line): |
| 89 return re.search(small_seconds, line) | 89 return re.search(small_seconds, line) |
| 90 | 90 |
| 91 def one_rule_per_line(line): | 91 def one_rule_per_line(line): |
| 92 return re.search('(.*:(?!\/\/)){2,}(?!.*[,{]\s*$)', line) | 92 return re.search(r'[_a-zA-Z0-9-]:(?!//)[^;]+;\s*[^ }]\s*', line) |
| 93 | 93 |
| 94 any_reg = re.compile(r':(?:-webkit-)?any\(.*?\)', re.DOTALL) | 94 any_reg = re.compile(r':(?:-webkit-)?any\(.*?\)', re.DOTALL) |
| 95 multi_sels = re.compile(r'(?:}[\n\s]*)?([^,]+,(?=[^{}]+?{).*[,{])\s*$', | 95 multi_sels = re.compile(r'(?:}[\n\s]*)?([^,]+,(?=[^{}]+?{).*[,{])\s*$', |
| 96 re.MULTILINE) | 96 re.MULTILINE) |
| 97 def one_selector_per_line(contents): | 97 def one_selector_per_line(contents): |
| 98 errors = [] | 98 errors = [] |
| 99 for b in re.finditer(multi_sels, re.sub(any_reg, '', contents)): | 99 for b in re.finditer(multi_sels, re.sub(any_reg, '', contents)): |
| 100 errors.append(' ' + b.group(1).strip()) | 100 errors.append(' ' + b.group(1).strip()) |
| 101 return errors | 101 return errors |
| 102 | 102 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) | 213 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
| 214 | 214 |
| 215 if results: | 215 if results: |
| 216 # Add your name if you're here often mucking around in the code. | 216 # Add your name if you're here often mucking around in the code. |
| 217 authors = ['dbeam@chromium.org'] | 217 authors = ['dbeam@chromium.org'] |
| 218 results.append(self.output_api.PresubmitNotifyResult( | 218 results.append(self.output_api.PresubmitNotifyResult( |
| 219 'Was the CSS checker useful? Send feedback or hate mail to %s.' % | 219 'Was the CSS checker useful? Send feedback or hate mail to %s.' % |
| 220 ', '.join(authors))) | 220 ', '.join(authors))) |
| 221 | 221 |
| 222 return results | 222 return results |
| OLD | NEW |