| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 def braces_have_space_before_and_nothing_after(line): | 61 def braces_have_space_before_and_nothing_after(line): |
| 62 return re.search(r'(?:^|\S){|{\s*\S+\s*$', line) | 62 return re.search(r'(?:^|\S){|{\s*\S+\s*$', line) |
| 63 | 63 |
| 64 def classes_use_dashes(line): | 64 def classes_use_dashes(line): |
| 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 # Ignore single frames in a @keyframe, i.e. 0% { margin: 50px; } |
| 72 frame_reg = r'\s*\d+%\s*{\s*[_a-zA-Z0-9-]+:(\s*[_a-zA-Z0-9-]+)+\s*;\s*}\s*' |
| 71 def close_brace_on_new_line(line): | 73 def close_brace_on_new_line(line): |
| 72 return (line.find('}') >= 0 and re.search(r'[^ }]', line)) | 74 return (line.find('}') >= 0 and re.search(r'[^ }]', line) and |
| 75 not re.match(frame_reg, line)) |
| 73 | 76 |
| 74 def colons_have_space_after(line): | 77 def colons_have_space_after(line): |
| 75 return re.search(r':(?!//)\S[^;]+;\s*', line) | 78 return re.search(r':(?!//)\S[^;]+;\s*', line) |
| 76 | 79 |
| 77 def favor_single_quotes(line): | 80 def favor_single_quotes(line): |
| 78 return line.find('"') >= 0 | 81 return line.find('"') >= 0 |
| 79 | 82 |
| 80 # Shared between hex_could_be_shorter and rgb_if_not_gray. | 83 # 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-]|$)' | 84 hex_reg = (r'#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})(?=[^_a-zA-Z0-9-]|$)' |
| 82 r'(?!.*(?:{.*|,\s*)$)') | 85 r'(?!.*(?:{.*|,\s*)$)') |
| 83 def hex_could_be_shorter(line): | 86 def hex_could_be_shorter(line): |
| 84 m = re.search(hex_reg, line) | 87 m = re.search(hex_reg, line) |
| 85 return (m and _collapseable_hex(m.group(1))) | 88 return (m and _is_gray(m.group(1)) and _collapseable_hex(m.group(1))) |
| 86 | 89 |
| 87 small_seconds = r'(?:^|[^_a-zA-Z0-9-])(0?\.[0-9]+)s(?!-?[_a-zA-Z0-9-])' | 90 small_seconds = r'(?:^|[^_a-zA-Z0-9-])(0?\.[0-9]+)s(?!-?[_a-zA-Z0-9-])' |
| 88 def milliseconds_for_small_times(line): | 91 def milliseconds_for_small_times(line): |
| 89 return re.search(small_seconds, line) | 92 return re.search(small_seconds, line) |
| 90 | 93 |
| 91 def one_rule_per_line(line): | 94 def one_rule_per_line(line): |
| 92 return re.search(r'[_a-zA-Z0-9-]:(?!//)[^;]+;\s*[^ }]\s*', line) | 95 return re.search(r'[_a-zA-Z0-9-]:(?!//)[^;]+;\s*[^ }]\s*', line) |
| 93 | 96 |
| 94 any_reg = re.compile(r':(?:-webkit-)?any\(.*?\)', re.DOTALL) | 97 any_reg = re.compile(r':(?:-webkit-)?any\(.*?\)', re.DOTALL) |
| 95 multi_sels = re.compile(r'(?:}[\n\s]*)?([^,]+,(?=[^{}]+?{).*[,{])\s*$', | 98 multi_sels = re.compile(r'(?:}[\n\s]*)?([^,]+,(?=[^{}]+?{).*[,{])\s*$', |
| 96 re.MULTILINE) | 99 re.MULTILINE) |
| 97 def one_selector_per_line(contents): | 100 def one_selector_per_line(contents): |
| 98 errors = [] | 101 errors = [] |
| 99 for b in re.finditer(multi_sels, re.sub(any_reg, '', contents)): | 102 for b in re.finditer(multi_sels, re.sub(any_reg, '', contents)): |
| 100 errors.append(' ' + b.group(1).strip()) | 103 errors.append(' ' + b.group(1).strip().splitlines()[-1:][0]) |
| 101 return errors | 104 return errors |
| 102 | 105 |
| 103 def rgb_if_not_gray(line): | 106 def rgb_if_not_gray(line): |
| 104 m = re.search(hex_reg, line) | 107 m = re.search(hex_reg, line) |
| 105 return (m and not _is_gray(m.group(1))) | 108 return (m and not _is_gray(m.group(1))) |
| 106 | 109 |
| 107 def suggest_ms_from_s(line): | 110 def suggest_ms_from_s(line): |
| 108 ms = int(float(re.search(small_seconds, line).group(1)) * 1000) | 111 ms = int(float(re.search(small_seconds, line).group(1)) * 1000) |
| 109 return ' (replace with %dms)' % ms | 112 return ' (replace with %dms)' % ms |
| 110 | 113 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 line = lines[lnum] | 205 line = lines[lnum] |
| 203 if check['test'](line): | 206 if check['test'](line): |
| 204 error = ' ' + line.strip() | 207 error = ' ' + line.strip() |
| 205 if 'after' in check: | 208 if 'after' in check: |
| 206 error += check['after'](line) | 209 error += check['after'](line) |
| 207 check_errors.append(error) | 210 check_errors.append(error) |
| 208 if len(check_errors) > 0: | 211 if len(check_errors) > 0: |
| 209 file_errors.append('- %s\n%s' % | 212 file_errors.append('- %s\n%s' % |
| 210 (check['desc'], '\n'.join(check_errors))) | 213 (check['desc'], '\n'.join(check_errors))) |
| 211 if file_errors: | 214 if file_errors: |
| 212 results.append(self.output_api.PresubmitError( | 215 results.append(self.output_api.PresubmitPromptWarning( |
| 213 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) | 216 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
| 214 | 217 |
| 215 if results: | 218 if results: |
| 216 # Add your name if you're here often mucking around in the code. | 219 # Add your name if you're here often mucking around in the code. |
| 217 authors = ['dbeam@chromium.org'] | 220 authors = ['dbeam@chromium.org'] |
| 218 results.append(self.output_api.PresubmitNotifyResult( | 221 results.append(self.output_api.PresubmitNotifyResult( |
| 219 'Was the CSS checker useful? Send feedback or hate mail to %s.' % | 222 'Was the CSS checker useful? Send feedback or hate mail to %s.' % |
| 220 ', '.join(authors))) | 223 ', '.join(authors))) |
| 221 | 224 |
| 222 return results | 225 return results |
| OLD | NEW |