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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 '--format', format, |
93 '--ignore-pattern \'!.eslintrc.js\'', | 93 '--ignore-pattern \'!.eslintrc.js\'', |
94 ' '.join(affected_js_files_paths)]) | 94 ' '.join(affected_js_files_paths)]) |
95 | 95 |
96 return [self.output_api.PresubmitError(output)] if output else [] | 96 return [self.output_api.PresubmitError(output)] if output else [] |
97 | 97 |
98 def WrapperTypeCheck(self, i, line): | |
99 """Check for wrappers (new String()) instead of builtins (string).""" | |
100 return self.RegexCheck(i, line, | |
101 r"(?:/\*)?\*.*?@(?:param|return|type) ?" # /** @param/@return/@type | |
102 r"{[^}]*\b(String|Boolean|Number)\b[^}]*}", # {(Boolean|Number|String)} | |
103 "Don't use wrapper types (i.e. new String() or @type {String})") | |
104 | |
105 def VarNameCheck(self, i, line): | 98 def VarNameCheck(self, i, line): |
106 """See the style guide. http://goo.gl/eQiXVW""" | 99 """See the style guide. http://goo.gl/eQiXVW""" |
107 return self.RegexCheck(i, line, | 100 return self.RegexCheck(i, line, |
108 r"var (?!g_\w+)(_?[a-z][a-zA-Z]*[_$][\w_$]*)(?<! \$)", | 101 r"var (?!g_\w+)(_?[a-z][a-zA-Z]*[_$][\w_$]*)(?<! \$)", |
109 "Please use var namesLikeThis <https://goo.gl/eQiXVW>") | 102 "Please use var namesLikeThis <https://goo.gl/eQiXVW>") |
110 | 103 |
111 def _GetErrorHighlight(self, start, length): | 104 def _GetErrorHighlight(self, start, length): |
112 """Takes a start position and a length, and produces a row of '^'s to | 105 """Takes a start position and a length, and produces a row of '^'s to |
113 highlight the corresponding part of a string. | 106 highlight the corresponding part of a string. |
114 """ | 107 """ |
(...skipping 18 matching lines...) Expand all Loading... |
133 | 126 |
134 for i, line in enumerate(f.NewContents(), start=1): | 127 for i, line in enumerate(f.NewContents(), start=1): |
135 error_lines += filter(None, [ | 128 error_lines += filter(None, [ |
136 self.ChromeSendCheck(i, line), | 129 self.ChromeSendCheck(i, line), |
137 self.CommentIfAndIncludeCheck(i, line), | 130 self.CommentIfAndIncludeCheck(i, line), |
138 self.ConstCheck(i, line), | 131 self.ConstCheck(i, line), |
139 self.EndJsDocCommentCheck(i, line), | 132 self.EndJsDocCommentCheck(i, line), |
140 self.ExtraDotInGenericCheck(i, line), | 133 self.ExtraDotInGenericCheck(i, line), |
141 self.InheritDocCheck(i, line), | 134 self.InheritDocCheck(i, line), |
142 self.PolymerLocalIdCheck(i, line), | 135 self.PolymerLocalIdCheck(i, line), |
143 self.WrapperTypeCheck(i, line), | |
144 self.VarNameCheck(i, line), | 136 self.VarNameCheck(i, line), |
145 ]) | 137 ]) |
146 | 138 |
147 if error_lines: | 139 if error_lines: |
148 error_lines = [ | 140 error_lines = [ |
149 'Found JavaScript style violations in %s:' % | 141 'Found JavaScript style violations in %s:' % |
150 f.LocalPath()] + error_lines | 142 f.LocalPath()] + error_lines |
151 results.append(self.output_api.PresubmitError('\n'.join(error_lines))) | 143 results.append(self.output_api.PresubmitError('\n'.join(error_lines))) |
152 | 144 |
153 if results: | 145 if results: |
154 results.append(self.output_api.PresubmitNotifyResult( | 146 results.append(self.output_api.PresubmitNotifyResult( |
155 'See the JavaScript style guide at ' | 147 'See the JavaScript style guide at ' |
156 'https://chromium.googlesource.com/chromium/src/+/master/styleguide/we
b/web.md#JavaScript')) | 148 'https://chromium.googlesource.com/chromium/src/+/master/styleguide/we
b/web.md#JavaScript')) |
157 | 149 |
158 return results | 150 return results |
OLD | NEW |