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 JS resources. | 5 """Presubmit script for Chromium JS resources. |
6 | 6 |
7 See chrome/browser/PRESUBMIT.py | 7 See chrome/browser/PRESUBMIT.py |
8 """ | 8 """ |
9 | 9 |
10 import regex_check | 10 import regex_check |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 highlight the corresponding part of a string. | 86 highlight the corresponding part of a string. |
87 """ | 87 """ |
88 return start * ' ' + length * '^' | 88 return start * ' ' + length * '^' |
89 | 89 |
90 def RunChecks(self): | 90 def RunChecks(self): |
91 """Check for violations of the Chromium JavaScript style guide. See | 91 """Check for violations of the Chromium JavaScript style guide. See |
92 https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/we
b.md#JavaScript | 92 https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/we
b.md#JavaScript |
93 """ | 93 """ |
94 results = [] | 94 results = [] |
95 | 95 |
96 affected_files = self.input_api.change.AffectedFiles( | 96 affected_files = self.input_api.AffectedFiles(file_filter=self.file_filter, |
97 file_filter=self.file_filter, | 97 include_deletes=False) |
98 include_deletes=False) | |
99 affected_js_files = filter(lambda f: f.LocalPath().endswith('.js'), | 98 affected_js_files = filter(lambda f: f.LocalPath().endswith('.js'), |
100 affected_files) | 99 affected_files) |
101 for f in affected_js_files: | 100 for f in affected_js_files: |
102 error_lines = [] | 101 error_lines = [] |
103 | 102 |
104 for i, line in enumerate(f.NewContents(), start=1): | 103 for i, line in enumerate(f.NewContents(), start=1): |
105 error_lines += filter(None, [ | 104 error_lines += filter(None, [ |
106 self.ChromeSendCheck(i, line), | 105 self.ChromeSendCheck(i, line), |
107 self.CommentIfAndIncludeCheck(i, line), | 106 self.CommentIfAndIncludeCheck(i, line), |
108 self.ConstCheck(i, line), | 107 self.ConstCheck(i, line), |
(...skipping 11 matching lines...) Expand all Loading... |
120 'Found JavaScript style violations in %s:' % | 119 'Found JavaScript style violations in %s:' % |
121 f.LocalPath()] + error_lines | 120 f.LocalPath()] + error_lines |
122 results.append(self.output_api.PresubmitError('\n'.join(error_lines))) | 121 results.append(self.output_api.PresubmitError('\n'.join(error_lines))) |
123 | 122 |
124 if results: | 123 if results: |
125 results.append(self.output_api.PresubmitNotifyResult( | 124 results.append(self.output_api.PresubmitNotifyResult( |
126 'See the JavaScript style guide at ' | 125 'See the JavaScript style guide at ' |
127 'https://chromium.googlesource.com/chromium/src/+/master/styleguide/we
b/web.md#JavaScript')) | 126 'https://chromium.googlesource.com/chromium/src/+/master/styleguide/we
b/web.md#JavaScript')) |
128 | 127 |
129 return results | 128 return results |
OLD | NEW |