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 depot_tools, and see | 8 for more details about the presubmit API built into depot_tools, 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 11 matching lines...) Expand all Loading... | |
| 22 # We use this a lot, so make a nick name variable. | 22 # We use this a lot, so make a nick name variable. |
| 23 re = self.input_api.re | 23 re = self.input_api.re |
| 24 | 24 |
| 25 def _collapseable_hex(s): | 25 def _collapseable_hex(s): |
| 26 return (len(s) == 6 and s[0] == s[1] and s[2] == s[3] and s[4] == s[5]) | 26 return (len(s) == 6 and s[0] == s[1] and s[2] == s[3] and s[4] == s[5]) |
| 27 | 27 |
| 28 def _is_gray(s): | 28 def _is_gray(s): |
| 29 return s[0] == s[1] == s[2] if len(s) == 3 else s[0:2] == s[2:4] == s[4:6] | 29 return s[0] == s[1] == s[2] if len(s) == 3 else s[0:2] == s[2:4] == s[4:6] |
| 30 | 30 |
| 31 def _remove_all(s): | 31 def _remove_all(s): |
| 32 s = _remove_ats(s) | |
| 32 s = _remove_grit(s) | 33 s = _remove_grit(s) |
| 33 s = _remove_ats(s) | |
| 34 s = _remove_comments(s) | 34 s = _remove_comments(s) |
| 35 s = _remove_mixins(s) | |
| 35 s = _remove_template_expressions(s) | 36 s = _remove_template_expressions(s) |
| 36 s = _remove_mixins(s) | 37 s = _remove_vars(s) |
| 37 return s | 38 return s |
| 38 | 39 |
| 39 def _remove_ats(s): | 40 def _remove_ats(s): |
| 40 at_reg = re.compile(r""" | 41 at_reg = re.compile(r""" |
| 41 @(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x | 42 @(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x |
| 42 (.*{.*?})+ # inner { curly } blocks, rules, and selector | 43 (.*{.*?})+ # inner { curly } blocks, rules, and selector |
| 43 .*?} # stuff up to the first end curly } | 44 .*?} # stuff up to the first end curly } |
| 44 """, | 45 """, |
| 45 re.DOTALL | re.VERBOSE) | 46 re.DOTALL | re.VERBOSE) |
| 46 return at_reg.sub('\\1', s) | 47 return at_reg.sub('\\1', s) |
| 47 | 48 |
| 48 def _remove_comments(s): | 49 def _remove_comments(s): |
| 49 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) | 50 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) |
| 50 | 51 |
| 51 def _remove_mixins(s): | 52 def _remove_mixins(s): |
| 52 return re.sub(re.compile(r'--[\d\w-]+: {.*?};', re.DOTALL), '', s) | 53 return re.sub(re.compile(r'--[\d\w-]+: {.*?};', re.DOTALL), '', s) |
| 53 | 54 |
| 54 def _remove_template_expressions(s): | |
| 55 return re.sub(re.compile(r'\${[^}]*}', re.DOTALL), '', s) | |
| 56 | |
| 57 def _remove_grit(s): | 55 def _remove_grit(s): |
| 58 grit_reg = re.compile(r""" | 56 grit_reg = re.compile(r""" |
| 59 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if> | 57 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if> |
| 60 <include[^>]+> # <include> | 58 <include[^>]+> # <include> |
| 61 """, | 59 """, |
| 62 re.DOTALL | re.VERBOSE) | 60 re.DOTALL | re.VERBOSE) |
| 63 return re.sub(grit_reg, '', s) | 61 return re.sub(grit_reg, '', s) |
| 64 | 62 |
| 63 def _remove_template_expressions(s): | |
| 64 return re.sub(re.compile(r'\${[^}]*}', re.DOTALL), '', s) | |
| 65 | |
| 66 def _remove_vars(s): | |
| 67 return re.sub(re.compile(r'--[\d\w-]+: [^;]+?;', re.DOTALL), '', s); | |
|
dschuyler
2016/09/15 23:17:36
How about entries like this
--foo: {
option: cho
dschuyler
2016/09/15 23:17:36
I think the \d isn't needed (if I'm wrong on
that
Dan Beam
2016/09/15 23:30:17
does that mean you want me to combine this with _r
dschuyler
2016/09/15 23:48:35
Ah, I see it now. Maybe just a comment saying that
Dan Beam
2016/09/17 02:06:19
Done.
dschuyler
2016/09/19 21:23:28
I'm pretty sure \d is redundant with \w within
a [
Dan Beam
2016/09/22 02:13:25
Done.
| |
| 68 | |
| 65 def _rgb_from_hex(s): | 69 def _rgb_from_hex(s): |
| 66 if len(s) == 3: | 70 if len(s) == 3: |
| 67 r, g, b = s[0] + s[0], s[1] + s[1], s[2] + s[2] | 71 r, g, b = s[0] + s[0], s[1] + s[1], s[2] + s[2] |
| 68 else: | 72 else: |
| 69 r, g, b = s[0:2], s[2:4], s[4:6] | 73 r, g, b = s[0:2], s[2:4], s[4:6] |
| 70 return int(r, base=16), int(g, base=16), int(b, base=16) | 74 return int(r, base=16), int(g, base=16), int(b, base=16) |
| 71 | 75 |
| 72 def _strip_prefix(s): | 76 def _strip_prefix(s): |
| 73 return re.sub(r'^-(?:o|ms|moz|khtml|webkit)-', '', s) | 77 return re.sub(r'^-(?:o|ms|moz|khtml|webkit)-', '', s) |
| 74 | 78 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 error += check['after'](line) | 407 error += check['after'](line) |
| 404 check_errors.append(error) | 408 check_errors.append(error) |
| 405 if len(check_errors) > 0: | 409 if len(check_errors) > 0: |
| 406 file_errors.append('- %s\n%s' % | 410 file_errors.append('- %s\n%s' % |
| 407 (check['desc'], '\n'.join(check_errors))) | 411 (check['desc'], '\n'.join(check_errors))) |
| 408 if file_errors: | 412 if file_errors: |
| 409 results.append(self.output_api.PresubmitPromptWarning( | 413 results.append(self.output_api.PresubmitPromptWarning( |
| 410 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) | 414 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
| 411 | 415 |
| 412 return results | 416 return results |
| OLD | NEW |