| 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 gcl/git cl, and see | 8 for more details about the presubmit API built into gcl/git cl, 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 26 matching lines...) Expand all Loading... |
| 37 results.extend( | 37 results.extend( |
| 38 input_api.canned_checks.RunUnitTests(input_api, output_api, tests)) | 38 input_api.canned_checks.RunUnitTests(input_api, output_api, tests)) |
| 39 | 39 |
| 40 import sys | 40 import sys |
| 41 old_path = sys.path | 41 old_path = sys.path |
| 42 | 42 |
| 43 try: | 43 try: |
| 44 sys.path.insert(0, resources) | 44 sys.path.insert(0, resources) |
| 45 from web_dev_style import css_checker, js_checker | 45 from web_dev_style import css_checker, js_checker |
| 46 | 46 |
| 47 # NOTE: This presubmit only scans affected files in this directory or in |
| 48 # subdirectories, that why we don't need to check for .startswith(resources) |
| 49 # here. |
| 50 def is_resource(f): |
| 51 return f.LocalPath().endswith(('.css', '.html', '.js')) |
| 52 |
| 47 # TODO(dbeam): Remove this directory filter eventually when ready. | 53 # TODO(dbeam): Remove this directory filter eventually when ready. |
| 48 dirs = ( | 54 dirs = ( |
| 49 path.join(resources, 'extensions'), | 55 path.join(resources, 'extensions'), |
| 50 path.join(resources, 'help'), | 56 path.join(resources, 'help'), |
| 51 path.join(resources, 'net_internals'), | 57 path.join(resources, 'net_internals'), |
| 52 path.join(resources, 'ntp4'), | 58 path.join(resources, 'ntp4'), |
| 53 path.join(resources, 'options2'), | 59 path.join(resources, 'options2'), |
| 54 path.join(resources, 'uber'), | 60 path.join(resources, 'uber'), |
| 55 ) | 61 ) |
| 56 def file_filter(affected_file): | 62 def certain_dirs(f): |
| 57 f = affected_file.AbsoluteLocalPath() | 63 return is_resource(f) and f.AbsoluteLocalPath().startswith(dirs) |
| 58 return (f.startswith(dirs) and f.endswith(('.css', '.html', '.js'))) | |
| 59 | 64 |
| 60 results.extend(css_checker.CSSChecker(input_api, output_api, | 65 results.extend(css_checker.CSSChecker(input_api, output_api, |
| 61 file_filter=file_filter).RunChecks()) | 66 file_filter=is_resource).RunChecks()) |
| 62 results.extend(js_checker.JSChecker(input_api, output_api, | 67 results.extend(js_checker.JSChecker(input_api, output_api, |
| 63 file_filter=file_filter).RunChecks()) | 68 file_filter=certain_dirs).RunChecks()) |
| 64 finally: | 69 finally: |
| 65 sys.path = old_path | 70 sys.path = old_path |
| 66 | 71 |
| 67 return results | 72 return results |
| OLD | NEW |