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 return _remove_grit(_remove_ats(_remove_comments(s))) | 32 return _remove_grit(_remove_ats(_remove_comments( |
| 33 _remove_replacement_tags(s)))) | |
|
Dan Beam
2015/07/09 19:26:01
maybe it's time to do:
tmp = s
tmp = _remove_
dschuyler
2015/07/14 00:56:17
Done.
| |
| 33 | 34 |
| 34 def _remove_ats(s): | 35 def _remove_ats(s): |
| 35 at_reg = re.compile(r""" | 36 at_reg = re.compile(r""" |
| 36 @(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x | 37 @(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x |
| 37 (.*{.*?})+ # inner { curly } blocks, rules, and selector | 38 (.*{.*?})+ # inner { curly } blocks, rules, and selector |
| 38 .*?} # stuff up to the first end curly } | 39 .*?} # stuff up to the first end curly } |
| 39 """, | 40 """, |
| 40 re.DOTALL | re.VERBOSE) | 41 re.DOTALL | re.VERBOSE) |
| 41 return at_reg.sub('\\1', s) | 42 return at_reg.sub('\\1', s) |
| 42 | 43 |
| 43 def _remove_comments(s): | 44 def _remove_comments(s): |
| 44 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) | 45 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) |
| 45 | 46 |
| 47 def _remove_replacement_tags(s): | |
|
Dan Beam
2015/07/09 19:26:01
nit: _remove_template_expressions
dschuyler
2015/07/14 00:56:17
Done.
| |
| 48 return re.sub(re.compile(r'\${[^}]*}', re.DOTALL), '', s) | |
|
Dan Beam
2015/07/09 19:26:01
can haz test in chrome/browser/test_presubmit.py?
| |
| 49 | |
| 46 def _remove_grit(s): | 50 def _remove_grit(s): |
| 47 grit_reg = re.compile(r""" | 51 grit_reg = re.compile(r""" |
| 48 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if> | 52 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if> |
| 49 <include[^>]+> # <include> | 53 <include[^>]+> # <include> |
| 50 """, | 54 """, |
| 51 re.DOTALL | re.VERBOSE) | 55 re.DOTALL | re.VERBOSE) |
| 52 return re.sub(grit_reg, '', s) | 56 return re.sub(grit_reg, '', s) |
| 53 | 57 |
| 54 def _rgb_from_hex(s): | 58 def _rgb_from_hex(s): |
| 55 if len(s) == 3: | 59 if len(s) == 3: |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) | 400 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
| 397 | 401 |
| 398 if results: | 402 if results: |
| 399 # Add your name if you're here often mucking around in the code. | 403 # Add your name if you're here often mucking around in the code. |
| 400 authors = ['dbeam@chromium.org'] | 404 authors = ['dbeam@chromium.org'] |
| 401 results.append(self.output_api.PresubmitNotifyResult( | 405 results.append(self.output_api.PresubmitNotifyResult( |
| 402 'Was the CSS checker useful? Send feedback or hate mail to %s.' % | 406 'Was the CSS checker useful? Send feedback or hate mail to %s.' % |
| 403 ', '.join(authors))) | 407 ', '.join(authors))) |
| 404 | 408 |
| 405 return results | 409 return results |
| OLD | NEW |