| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 """Checks for use of 'document.getElementById' instead of '$'.""" | 48 """Checks for use of 'document.getElementById' instead of '$'.""" |
| 49 return self.RegexCheck(i, line, r"(document\.getElementById)\('", | 49 return self.RegexCheck(i, line, r"(document\.getElementById)\('", |
| 50 "Use $('id') or getSVGElement('id') from chrome://resources/js/util.js " | 50 "Use $('id') or getSVGElement('id') from chrome://resources/js/util.js " |
| 51 "instead of document.getElementById('id')") | 51 "instead of document.getElementById('id')") |
| 52 | 52 |
| 53 def InheritDocCheck(self, i, line): | 53 def InheritDocCheck(self, i, line): |
| 54 """Checks for use of '@inheritDoc' instead of '@override'.""" | 54 """Checks for use of '@inheritDoc' instead of '@override'.""" |
| 55 return self.RegexCheck(i, line, r"\* (@inheritDoc)", | 55 return self.RegexCheck(i, line, r"\* (@inheritDoc)", |
| 56 "@inheritDoc is deprecated, use @override instead") | 56 "@inheritDoc is deprecated, use @override instead") |
| 57 | 57 |
| 58 def PolymerLocalIdCheck(self, i, line): |
| 59 """Checks for use of element.$.localId.""" |
| 60 return self.RegexCheck(i, line, r"(?<!this)(\.\$)[\[\.]", |
| 61 "Please only use this.$.localId, not element.$.localId") |
| 62 |
| 58 def WrapperTypeCheck(self, i, line): | 63 def WrapperTypeCheck(self, i, line): |
| 59 """Check for wrappers (new String()) instead of builtins (string).""" | 64 """Check for wrappers (new String()) instead of builtins (string).""" |
| 60 return self.RegexCheck(i, line, | 65 return self.RegexCheck(i, line, |
| 61 r"(?:/\*)?\*.*?@(?:param|return|type) ?" # /** @param/@return/@type | 66 r"(?:/\*)?\*.*?@(?:param|return|type) ?" # /** @param/@return/@type |
| 62 r"{[^}]*\b(String|Boolean|Number)\b[^}]*}", # {(Boolean|Number|String)} | 67 r"{[^}]*\b(String|Boolean|Number)\b[^}]*}", # {(Boolean|Number|String)} |
| 63 "Don't use wrapper types (i.e. new String() or @type {String})") | 68 "Don't use wrapper types (i.e. new String() or @type {String})") |
| 64 | 69 |
| 65 def VarNameCheck(self, i, line): | 70 def VarNameCheck(self, i, line): |
| 66 """See the style guide. http://goo.gl/uKir6""" | 71 """See the style guide. http://goo.gl/uKir6""" |
| 67 return self.RegexCheck(i, line, | 72 return self.RegexCheck(i, line, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 # * the 'const' keyword | 226 # * the 'const' keyword |
| 222 # * Passing an empty array to 'chrome.send()' | 227 # * Passing an empty array to 'chrome.send()' |
| 223 for i, line in enumerate(f.NewContents(), start=1): | 228 for i, line in enumerate(f.NewContents(), start=1): |
| 224 error_lines += filter(None, [ | 229 error_lines += filter(None, [ |
| 225 self.ChromeSendCheck(i, line), | 230 self.ChromeSendCheck(i, line), |
| 226 self.ConstCheck(i, line), | 231 self.ConstCheck(i, line), |
| 227 self.GetElementByIdCheck(i, line), | 232 self.GetElementByIdCheck(i, line), |
| 228 self.EndJsDocCommentCheck(i, line), | 233 self.EndJsDocCommentCheck(i, line), |
| 229 self.ExtraDotInGenericCheck(i, line), | 234 self.ExtraDotInGenericCheck(i, line), |
| 230 self.InheritDocCheck(i, line), | 235 self.InheritDocCheck(i, line), |
| 236 self.PolymerLocalIdCheck(i, line), |
| 231 self.WrapperTypeCheck(i, line), | 237 self.WrapperTypeCheck(i, line), |
| 232 self.VarNameCheck(i, line), | 238 self.VarNameCheck(i, line), |
| 233 ]) | 239 ]) |
| 234 | 240 |
| 235 # Use closure linter to check for several different errors. | 241 # Use closure linter to check for several different errors. |
| 236 lint_errors = self.ClosureLint(self.input_api.os_path.join( | 242 lint_errors = self.ClosureLint(self.input_api.os_path.join( |
| 237 self.input_api.change.RepositoryRoot(), f.LocalPath())) | 243 self.input_api.change.RepositoryRoot(), f.LocalPath())) |
| 238 | 244 |
| 239 for error in lint_errors: | 245 for error in lint_errors: |
| 240 highlight = self._GetErrorHighlight( | 246 highlight = self._GetErrorHighlight( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 254 results.append(self._MakeErrorOrWarning( | 260 results.append(self._MakeErrorOrWarning( |
| 255 '\n'.join(error_lines), f.AbsoluteLocalPath())) | 261 '\n'.join(error_lines), f.AbsoluteLocalPath())) |
| 256 | 262 |
| 257 if results: | 263 if results: |
| 258 results.append(self.output_api.PresubmitNotifyResult( | 264 results.append(self.output_api.PresubmitNotifyResult( |
| 259 'See the JavaScript style guide at ' | 265 'See the JavaScript style guide at ' |
| 260 'http://www.chromium.org/developers/web-development-style-guide' | 266 'http://www.chromium.org/developers/web-development-style-guide' |
| 261 '#TOC-JavaScript')) | 267 '#TOC-JavaScript')) |
| 262 | 268 |
| 263 return results | 269 return results |
| OLD | NEW |