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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 def InheritDocCheck(self, i, line): | 55 def InheritDocCheck(self, i, line): |
56 """Checks for use of '@inheritDoc' instead of '@override'.""" | 56 """Checks for use of '@inheritDoc' instead of '@override'.""" |
57 return self.RegexCheck(i, line, r"\* (@inheritDoc)", | 57 return self.RegexCheck(i, line, r"\* (@inheritDoc)", |
58 "@inheritDoc is deprecated, use @override instead") | 58 "@inheritDoc is deprecated, use @override instead") |
59 | 59 |
60 def PolymerLocalIdCheck(self, i, line): | 60 def PolymerLocalIdCheck(self, i, line): |
61 """Checks for use of element.$.localId.""" | 61 """Checks for use of element.$.localId.""" |
62 return self.RegexCheck(i, line, r"(?<!this)(\.\$)[\[\.]", | 62 return self.RegexCheck(i, line, r"(?<!this)(\.\$)[\[\.]", |
63 "Please only use this.$.localId, not element.$.localId") | 63 "Please only use this.$.localId, not element.$.localId") |
64 | 64 |
65 def RunEsLintChecks(self, affected_js_files): | 65 def RunEsLintChecks(self, affected_js_files, format='stylish'): |
66 """Runs lint checks using ESLint. The ESLint rules being applied are defined | 66 """Runs lint checks using ESLint. The ESLint rules being applied are defined |
67 in the .eslintrc.js configuration file. | 67 in the .eslintrc.js configuration file. |
68 """ | 68 """ |
69 os_path = self.input_api.os_path | 69 os_path = self.input_api.os_path |
70 | 70 |
71 try: | 71 try: |
72 # Import ESLint. | 72 # Import ESLint. |
73 _HERE_PATH = os_path.dirname(os_path.realpath(__file__)) | 73 _HERE_PATH = os_path.dirname(os_path.realpath(__file__)) |
74 _SRC_PATH = os_path.normpath(os_path.join(_HERE_PATH, '..', '..')) | 74 _SRC_PATH = os_path.normpath(os_path.join(_HERE_PATH, '..', '..')) |
75 import sys | 75 import sys |
76 old_sys_path = sys.path[:] | 76 old_sys_path = sys.path[:] |
77 sys.path.append(os_path.join(_SRC_PATH, 'third_party', 'node')) | 77 sys.path.append(os_path.join(_SRC_PATH, 'third_party', 'node')) |
78 import node, node_modules | 78 import node, node_modules |
79 finally: | 79 finally: |
80 sys.path = old_sys_path | 80 sys.path = old_sys_path |
81 | 81 |
82 # Extract paths to be passed to ESLint. | 82 # Extract paths to be passed to ESLint. |
83 affected_js_files_paths = [] | 83 affected_js_files_paths = [] |
84 presubmit_path = self.input_api.PresubmitLocalPath() | 84 presubmit_path = self.input_api.PresubmitLocalPath() |
85 for f in affected_js_files: | 85 for f in affected_js_files: |
86 affected_js_files_paths.append( | 86 affected_js_files_paths.append( |
87 os_path.relpath(f.AbsoluteLocalPath(), presubmit_path)) | 87 os_path.relpath(f.AbsoluteLocalPath(), presubmit_path)) |
88 | 88 |
89 output = node.RunNode([ | 89 output = node.RunNode([ |
90 node_modules.PathToEsLint(), | 90 node_modules.PathToEsLint(), |
91 '--color', | 91 '--color', |
| 92 '--format', format, |
92 '--ignore-pattern \'!.eslintrc.js\'', | 93 '--ignore-pattern \'!.eslintrc.js\'', |
93 ' '.join(affected_js_files_paths)]) | 94 ' '.join(affected_js_files_paths)]) |
94 | 95 |
95 return [self.output_api.PresubmitError(output)] if output else [] | 96 return [self.output_api.PresubmitError(output)] if output else [] |
96 | 97 |
97 def WrapperTypeCheck(self, i, line): | 98 def WrapperTypeCheck(self, i, line): |
98 """Check for wrappers (new String()) instead of builtins (string).""" | 99 """Check for wrappers (new String()) instead of builtins (string).""" |
99 return self.RegexCheck(i, line, | 100 return self.RegexCheck(i, line, |
100 r"(?:/\*)?\*.*?@(?:param|return|type) ?" # /** @param/@return/@type | 101 r"(?:/\*)?\*.*?@(?:param|return|type) ?" # /** @param/@return/@type |
101 r"{[^}]*\b(String|Boolean|Number)\b[^}]*}", # {(Boolean|Number|String)} | 102 r"{[^}]*\b(String|Boolean|Number)\b[^}]*}", # {(Boolean|Number|String)} |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 'Found JavaScript style violations in %s:' % | 149 'Found JavaScript style violations in %s:' % |
149 f.LocalPath()] + error_lines | 150 f.LocalPath()] + error_lines |
150 results.append(self.output_api.PresubmitError('\n'.join(error_lines))) | 151 results.append(self.output_api.PresubmitError('\n'.join(error_lines))) |
151 | 152 |
152 if results: | 153 if results: |
153 results.append(self.output_api.PresubmitNotifyResult( | 154 results.append(self.output_api.PresubmitNotifyResult( |
154 'See the JavaScript style guide at ' | 155 'See the JavaScript style guide at ' |
155 'https://chromium.googlesource.com/chromium/src/+/master/styleguide/we
b/web.md#JavaScript')) | 156 'https://chromium.googlesource.com/chromium/src/+/master/styleguide/we
b/web.md#JavaScript')) |
156 | 157 |
157 return results | 158 return results |
OLD | NEW |