| 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 s = _remove_grit(s) |
| 33 s = _remove_ats(s) |
| 34 s = _remove_comments(s) |
| 35 s = _remove_template_expressions(s) |
| 36 return s |
| 33 | 37 |
| 34 def _remove_ats(s): | 38 def _remove_ats(s): |
| 35 at_reg = re.compile(r""" | 39 at_reg = re.compile(r""" |
| 36 @(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x | 40 @(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x |
| 37 (.*{.*?})+ # inner { curly } blocks, rules, and selector | 41 (.*{.*?})+ # inner { curly } blocks, rules, and selector |
| 38 .*?} # stuff up to the first end curly } | 42 .*?} # stuff up to the first end curly } |
| 39 """, | 43 """, |
| 40 re.DOTALL | re.VERBOSE) | 44 re.DOTALL | re.VERBOSE) |
| 41 return at_reg.sub('\\1', s) | 45 return at_reg.sub('\\1', s) |
| 42 | 46 |
| 43 def _remove_comments(s): | 47 def _remove_comments(s): |
| 44 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) | 48 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) |
| 45 | 49 |
| 50 def _remove_template_expressions(s): |
| 51 return re.sub(re.compile(r'\${[^}]*}', re.DOTALL), '', s) |
| 52 |
| 46 def _remove_grit(s): | 53 def _remove_grit(s): |
| 47 grit_reg = re.compile(r""" | 54 grit_reg = re.compile(r""" |
| 48 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if> | 55 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if> |
| 49 <include[^>]+> # <include> | 56 <include[^>]+> # <include> |
| 50 """, | 57 """, |
| 51 re.DOTALL | re.VERBOSE) | 58 re.DOTALL | re.VERBOSE) |
| 52 return re.sub(grit_reg, '', s) | 59 return re.sub(grit_reg, '', s) |
| 53 | 60 |
| 54 def _rgb_from_hex(s): | 61 def _rgb_from_hex(s): |
| 55 if len(s) == 3: | 62 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)))) | 403 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
| 397 | 404 |
| 398 if results: | 405 if results: |
| 399 # Add your name if you're here often mucking around in the code. | 406 # Add your name if you're here often mucking around in the code. |
| 400 authors = ['dbeam@chromium.org'] | 407 authors = ['dbeam@chromium.org'] |
| 401 results.append(self.output_api.PresubmitNotifyResult( | 408 results.append(self.output_api.PresubmitNotifyResult( |
| 402 'Was the CSS checker useful? Send feedback or hate mail to %s.' % | 409 'Was the CSS checker useful? Send feedback or hate mail to %s.' % |
| 403 ', '.join(authors))) | 410 ', '.join(authors))) |
| 404 | 411 |
| 405 return results | 412 return results |
| OLD | NEW |