| OLD | NEW |
| 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 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 import re | 5 import re |
| 6 | 6 |
| 7 import eslint | 7 import eslint |
| 8 from py_vulcanize import strip_js_comments | 8 from py_vulcanize import strip_js_comments |
| 9 | 9 |
| 10 from catapult_build import parse_html | 10 from catapult_build import parse_html |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 for f in affected_js_files: | 77 for f in affected_js_files: |
| 78 contents = list(f.NewContents()) | 78 contents = list(f.NewContents()) |
| 79 error_lines += CheckStrictMode( | 79 error_lines += CheckStrictMode( |
| 80 '\n'.join(contents), | 80 '\n'.join(contents), |
| 81 is_html_file=f.LocalPath().endswith('.html')) | 81 is_html_file=f.LocalPath().endswith('.html')) |
| 82 | 82 |
| 83 for i, line in enumerate(contents, start=1): | 83 for i, line in enumerate(contents, start=1): |
| 84 error_lines += filter(None, [self.ConstCheck(i, line)]) | 84 error_lines += filter(None, [self.ConstCheck(i, line)]) |
| 85 | 85 |
| 86 if affected_js_files: | 86 if affected_js_files: |
| 87 eslint_output = eslint.RunEslintOnFiles( | 87 success, eslint_output = eslint.RunEslint( |
| 88 [f.AbsoluteLocalPath() for f in affected_js_files]).rstrip() | 88 [f.AbsoluteLocalPath() for f in affected_js_files]) |
| 89 | 89 |
| 90 if eslint_output: | 90 if not success: |
| 91 error_lines.append('\neslint found lint errors:') | 91 error_lines.append('\neslint found lint errors:') |
| 92 error_lines.append(eslint_output) | 92 error_lines.append(eslint_output) |
| 93 | 93 |
| 94 if error_lines: | 94 if error_lines: |
| 95 error_lines.insert(0, 'Found JavaScript style violations:') | 95 error_lines.insert(0, 'Found JavaScript style violations:') |
| 96 results.append( | 96 results.append( |
| 97 _MakeErrorOrWarning(self.output_api, '\n'.join(error_lines))) | 97 _MakeErrorOrWarning(self.output_api, '\n'.join(error_lines))) |
| 98 | 98 |
| 99 return results | 99 return results |
| 100 | 100 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 140 |
| 141 def RunChecks(input_api, output_api, excluded_paths=None): | 141 def RunChecks(input_api, output_api, excluded_paths=None): |
| 142 | 142 |
| 143 def ShouldCheck(affected_file): | 143 def ShouldCheck(affected_file): |
| 144 if not excluded_paths: | 144 if not excluded_paths: |
| 145 return True | 145 return True |
| 146 path = affected_file.LocalPath() | 146 path = affected_file.LocalPath() |
| 147 return not any(re.match(pattern, path) for pattern in excluded_paths) | 147 return not any(re.match(pattern, path) for pattern in excluded_paths) |
| 148 | 148 |
| 149 return JSChecker(input_api, output_api, file_filter=ShouldCheck).RunChecks() | 149 return JSChecker(input_api, output_api, file_filter=ShouldCheck).RunChecks() |
| OLD | NEW |