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