| 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 'test': zero_width_lengths, | 378 'test': zero_width_lengths, |
| 379 'multiline': True, | 379 'multiline': True, |
| 380 }, | 380 }, |
| 381 ] | 381 ] |
| 382 | 382 |
| 383 results = [] | 383 results = [] |
| 384 affected_files = self.input_api.AffectedFiles(include_deletes=False, | 384 affected_files = self.input_api.AffectedFiles(include_deletes=False, |
| 385 file_filter=self.file_filter) | 385 file_filter=self.file_filter) |
| 386 files = [] | 386 files = [] |
| 387 for f in affected_files: | 387 for f in affected_files: |
| 388 file_contents = '\n'.join(f.NewContents()) | |
| 389 path = f.LocalPath() | 388 path = f.LocalPath() |
| 389 |
| 390 is_html = path.endswith('.html') |
| 391 if not is_html and not path.endswith('.css'): |
| 392 continue |
| 393 |
| 394 # Remove all /*comments*/, @at-keywords, and grit <if|include> tags; we're |
| 395 # not using a real parser. TODO(dbeam): Check alpha in <if> blocks. |
| 396 file_contents = _remove_all('\n'.join(f.NewContents())) |
| 397 |
| 390 # Handle CSS files and HTML files with inline styles. | 398 # Handle CSS files and HTML files with inline styles. |
| 391 if path.endswith('.html'): | 399 if is_html: |
| 392 file_contents = _extract_inline_style(file_contents) | 400 file_contents = _extract_inline_style(file_contents) |
| 393 | 401 |
| 394 if path.endswith('.html') or path.endswith('.css'): | 402 files.append((path, file_contents)) |
| 395 # Remove all /*comments*/, @at-keywords, and grit <if|include> tags; | |
| 396 # we're not using a real parser. TODO(dbeam): Check alpha in <if> | |
| 397 # blocks. | |
| 398 file_contents = _remove_all(file_contents) | |
| 399 files.append((path, file_contents)) | |
| 400 | 403 |
| 401 for f in files: | 404 for f in files: |
| 402 file_errors = [] | 405 file_errors = [] |
| 403 for check in added_or_modified_files_checks: | 406 for check in added_or_modified_files_checks: |
| 404 # If the check is multiline, it receives the whole file and gives us | 407 # If the check is multiline, it receives the whole file and gives us |
| 405 # back a list of things wrong. If the check isn't multiline, we pass it | 408 # back a list of things wrong. If the check isn't multiline, we pass it |
| 406 # each line and the check returns something truthy if there's an issue. | 409 # each line and the check returns something truthy if there's an issue. |
| 407 if ('multiline' in check and check['multiline']): | 410 if ('multiline' in check and check['multiline']): |
| 408 assert not 'after' in check | 411 assert not 'after' in check |
| 409 check_errors = check['test'](f[1]) | 412 check_errors = check['test'](f[1]) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 420 error += check['after'](line) | 423 error += check['after'](line) |
| 421 check_errors.append(error) | 424 check_errors.append(error) |
| 422 if len(check_errors) > 0: | 425 if len(check_errors) > 0: |
| 423 file_errors.append('- %s\n%s' % | 426 file_errors.append('- %s\n%s' % |
| 424 (check['desc'], '\n'.join(check_errors))) | 427 (check['desc'], '\n'.join(check_errors))) |
| 425 if file_errors: | 428 if file_errors: |
| 426 results.append(self.output_api.PresubmitPromptWarning( | 429 results.append(self.output_api.PresubmitPromptWarning( |
| 427 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) | 430 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) |
| 428 | 431 |
| 429 return results | 432 return results |
| OLD | NEW |