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 https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/web.md | 9 https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/web.md |
10 for the rules we're checking against here. | 10 for the rules we're checking against here. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 {\s*\S+\s* # selector { with stuff after it | 93 {\s*\S+\s* # selector { with stuff after it |
94 $ # must be at the end of a line | 94 $ # must be at the end of a line |
95 """, | 95 """, |
96 re.VERBOSE) | 96 re.VERBOSE) |
97 return brace_space_reg.search(line) | 97 return brace_space_reg.search(line) |
98 | 98 |
99 def classes_use_dashes(line): | 99 def classes_use_dashes(line): |
100 # Intentionally dumbed down version of CSS 2.1 grammar for class without | 100 # Intentionally dumbed down version of CSS 2.1 grammar for class without |
101 # non-ASCII, escape chars, or whitespace. | 101 # non-ASCII, escape chars, or whitespace. |
102 class_reg = re.compile(r""" | 102 class_reg = re.compile(r""" |
103 \.(-?[\w-]+).* # ., then maybe -, then alpha numeric and - | 103 (?<!')\.(-?[\w-]+).* # ., then maybe -, then alpha numeric and - |
104 [,{]\s*$ # selectors should end with a , or { | 104 [,{]\s*$ # selectors should end with a , or { |
105 """, | 105 """, |
106 re.VERBOSE) | 106 re.VERBOSE) |
107 m = class_reg.search(line) | 107 m = class_reg.search(line) |
108 if not m: | 108 if not m: |
109 return False | 109 return False |
110 class_name = m.group(1) | 110 class_name = m.group(1) |
111 return class_name.lower() != class_name or '_' in class_name | 111 return class_name.lower() != class_name or '_' in class_name |
112 | 112 |
113 end_mixin_reg = re.compile(r'\s*};\s*$') | 113 end_mixin_reg = re.compile(r'\s*};\s*$') |
114 | 114 |
115 def close_brace_on_new_line(line): | 115 def close_brace_on_new_line(line): |
116 # Ignore single frames in a @keyframe, i.e. 0% { margin: 50px; } | 116 # Ignore single frames in a @keyframe, i.e. 0% { margin: 50px; } |
117 frame_reg = re.compile(r""" | 117 frame_reg = re.compile(r""" |
118 \s*(from|to|\d+%)\s*{ # 50% { | 118 \s*(from|to|\d+%)\s*{ # 50% { |
119 \s*[\w-]+: # rule: | 119 \s*[\w-]+: # rule: |
120 (\s*[\w\(\), -]+)+\s*; # value; | 120 (\s*[\w\(\), -\.]+)+\s*; # value; |
121 \s*}\s* # } | 121 \s*}\s* # } |
122 """, | 122 """, |
123 re.VERBOSE) | 123 re.VERBOSE) |
124 return ('}' in line and re.search(r'[^ }]', line) and | 124 return ('}' in line and re.search(r'[^ }]', line) and |
125 not frame_reg.match(line) and not end_mixin_reg.match(line)) | 125 not frame_reg.match(line) and not end_mixin_reg.match(line)) |
126 | 126 |
127 def colons_have_space_after(line): | 127 def colons_have_space_after(line): |
128 colon_space_reg = re.compile(r""" | 128 colon_space_reg = re.compile(r""" |
129 (?<!data) # ignore data URIs | 129 (?<!data) # ignore data URIs |
130 :(?!//) # ignore url(http://), etc. | 130 :(?!//) # ignore url(http://), etc. |
131 \S[^;]+;\s* # only catch one-line rules for now | 131 \S[^;]+;\s* # only catch one-line rules for now |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 hsl_reg = re.compile(r""" | 294 hsl_reg = re.compile(r""" |
295 hsl\([^\)]* # hsl(maybestuff | 295 hsl\([^\)]* # hsl(maybestuff |
296 (?:[, ]|(?<=\()) # a comma or space not followed by a ( | 296 (?:[, ]|(?<=\()) # a comma or space not followed by a ( |
297 (?:0?\.?)?0% # some equivalent to 0% | 297 (?:0?\.?)?0% # some equivalent to 0% |
298 """, | 298 """, |
299 re.VERBOSE) | 299 re.VERBOSE) |
300 zeros_reg = re.compile(r""" | 300 zeros_reg = re.compile(r""" |
301 ^.*(?:^|[^0-9.]) # start/non-number | 301 ^.*(?:^|[^0-9.]) # start/non-number |
302 (?:\.0|0(?:\.0? # .0, 0, or 0.0 | 302 (?:\.0|0(?:\.0? # .0, 0, or 0.0 |
303 |px|em|%|in|cm|mm|pc|pt|ex)) # a length unit | 303 |px|em|%|in|cm|mm|pc|pt|ex)) # a length unit |
304 (?:\D|$) # non-number/end | 304 (?!svg|png|jpg)(?:\D|$) # non-number/end |
305 (?=[^{}]+?}).*$ # only { rules } | 305 (?=[^{}]+?}).*$ # only { rules } |
306 """, | 306 """, |
307 re.MULTILINE | re.VERBOSE) | 307 re.MULTILINE | re.VERBOSE) |
308 errors = [] | 308 errors = [] |
309 for z in re.finditer(zeros_reg, contents): | 309 for z in re.finditer(zeros_reg, contents): |
310 first_line = z.group(0).strip().splitlines()[0] | 310 first_line = z.group(0).strip().splitlines()[0] |
311 if not hsl_reg.search(first_line): | 311 if not hsl_reg.search(first_line): |
312 errors.append(' ' + first_line) | 312 errors.append(' ' + first_line) |
313 return errors | 313 return errors |
314 | 314 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 error += check['after'](line) | 423 error += check['after'](line) |
424 check_errors.append(error) | 424 check_errors.append(error) |
425 if len(check_errors) > 0: | 425 if len(check_errors) > 0: |
426 file_errors.append('- %s\n%s' % | 426 file_errors.append('- %s\n%s' % |
427 (check['desc'], '\n'.join(check_errors))) | 427 (check['desc'], '\n'.join(check_errors))) |
428 if file_errors: | 428 if file_errors: |
429 results.append(self.output_api.PresubmitPromptWarning( | 429 results.append(self.output_api.PresubmitPromptWarning( |
430 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) | 430 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
431 | 431 |
432 return results | 432 return results |
OLD | NEW |