| 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 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 def _remove_all(s): | 31 def _remove_all(s): |
| 32 s = _remove_grit(s) | 32 s = _remove_grit(s) |
| 33 s = _remove_ats(s) | 33 s = _remove_ats(s) |
| 34 s = _remove_comments(s) | 34 s = _remove_comments(s) |
| 35 s = _remove_template_expressions(s) | 35 s = _remove_template_expressions(s) |
| 36 s = _remove_mixins(s) | 36 s = _remove_mixins(s) |
| 37 return s | 37 return s |
| 38 | 38 |
| 39 def _extract_inline_style(s): | 39 def _extract_inline_style(s): |
| 40 return '\n'.join(re.findall(r'<style>([^<]*)<\/style>', s)) | 40 return '\n'.join(re.findall(r'<style\b[^>]*>([^<]*)<\/style>', s)) |
| 41 | 41 |
| 42 def _remove_ats(s): | 42 def _remove_ats(s): |
| 43 at_reg = re.compile(r""" | 43 at_reg = re.compile(r""" |
| 44 @(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x | 44 @(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x |
| 45 (.*{.*?})+ # inner { curly } blocks, rules, and selector | 45 (.*{.*?})+ # inner { curly } blocks, rules, and selector |
| 46 .*?} # stuff up to the first end curly } | 46 .*?} # stuff up to the first end curly } |
| 47 """, | 47 """, |
| 48 re.DOTALL | re.VERBOSE) | 48 re.DOTALL | re.VERBOSE) |
| 49 return at_reg.sub('\\1', s) | 49 return at_reg.sub('\\1', s) |
| 50 | 50 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 if path.endswith('.html') or path.endswith('.css'): | 387 if path.endswith('.html') or path.endswith('.css'): |
| 388 # Remove all /*comments*/, @at-keywords, and grit <if|include> tags; | 388 # Remove all /*comments*/, @at-keywords, and grit <if|include> tags; |
| 389 # we're not using a real parser. TODO(dbeam): Check alpha in <if> | 389 # we're not using a real parser. TODO(dbeam): Check alpha in <if> |
| 390 # blocks. | 390 # blocks. |
| 391 file_contents = _remove_all(file_contents) | 391 file_contents = _remove_all(file_contents) |
| 392 files.append((path, file_contents)) | 392 files.append((path, file_contents)) |
| 393 | 393 |
| 394 for f in files: | 394 for f in files: |
| 395 file_errors = [] | 395 file_errors = [] |
| 396 for check in added_or_modified_files_checks: | 396 for check in added_or_modified_files_checks: |
| 397 # If the check is multiline, it receieves the whole file and gives us | 397 # If the check is multiline, it receives the whole file and gives us |
| 398 # back a list of things wrong. If the check isn't multiline, we pass it | 398 # back a list of things wrong. If the check isn't multiline, we pass it |
| 399 # each line and the check returns something truthy if there's an issue. | 399 # each line and the check returns something truthy if there's an issue. |
| 400 if ('multiline' in check and check['multiline']): | 400 if ('multiline' in check and check['multiline']): |
| 401 assert not 'after' in check | 401 assert not 'after' in check |
| 402 check_errors = check['test'](f[1]) | 402 check_errors = check['test'](f[1]) |
| 403 if len(check_errors) > 0: | 403 if len(check_errors) > 0: |
| 404 file_errors.append('- %s\n%s' % | 404 file_errors.append('- %s\n%s' % |
| 405 (check['desc'], '\n'.join(check_errors).rstrip())) | 405 (check['desc'], '\n'.join(check_errors).rstrip())) |
| 406 else: | 406 else: |
| 407 check_errors = [] | 407 check_errors = [] |
| 408 lines = f[1].splitlines() | 408 lines = f[1].splitlines() |
| 409 for lnum, line in enumerate(lines): | 409 for lnum, line in enumerate(lines): |
| 410 if check['test'](line): | 410 if check['test'](line): |
| 411 error = ' ' + line.strip() | 411 error = ' ' + line.strip() |
| 412 if 'after' in check: | 412 if 'after' in check: |
| 413 error += check['after'](line) | 413 error += check['after'](line) |
| 414 check_errors.append(error) | 414 check_errors.append(error) |
| 415 if len(check_errors) > 0: | 415 if len(check_errors) > 0: |
| 416 file_errors.append('- %s\n%s' % | 416 file_errors.append('- %s\n%s' % |
| 417 (check['desc'], '\n'.join(check_errors))) | 417 (check['desc'], '\n'.join(check_errors))) |
| 418 if file_errors: | 418 if file_errors: |
| 419 results.append(self.output_api.PresubmitPromptWarning( | 419 results.append(self.output_api.PresubmitPromptWarning( |
| 420 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) | 420 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
| 421 | 421 |
| 422 return results | 422 return results |
| OLD | NEW |