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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 "Please only use this.$.localId, not element.$.localId") | 69 "Please only use this.$.localId, not element.$.localId") |
70 | 70 |
71 def WrapperTypeCheck(self, i, line): | 71 def WrapperTypeCheck(self, i, line): |
72 """Check for wrappers (new String()) instead of builtins (string).""" | 72 """Check for wrappers (new String()) instead of builtins (string).""" |
73 return self.RegexCheck(i, line, | 73 return self.RegexCheck(i, line, |
74 r"(?:/\*)?\*.*?@(?:param|return|type) ?" # /** @param/@return/@type | 74 r"(?:/\*)?\*.*?@(?:param|return|type) ?" # /** @param/@return/@type |
75 r"{[^}]*\b(String|Boolean|Number)\b[^}]*}", # {(Boolean|Number|String)} | 75 r"{[^}]*\b(String|Boolean|Number)\b[^}]*}", # {(Boolean|Number|String)} |
76 "Don't use wrapper types (i.e. new String() or @type {String})") | 76 "Don't use wrapper types (i.e. new String() or @type {String})") |
77 | 77 |
78 def VarNameCheck(self, i, line): | 78 def VarNameCheck(self, i, line): |
79 """See the style guide. http://goo.gl/uKir6""" | 79 """See the style guide. http://goo.gl/eQiXVW""" |
80 return self.RegexCheck(i, line, | 80 return self.RegexCheck(i, line, |
81 r"var (?!g_\w+)([a-z]*[_$][\w_$]*)(?<! \$)", | 81 r"var (?!g_\w+)(_?[a-z][a-zA-Z]*[_$][\w_$]*)(?<! \$)", |
82 "Please use var namesLikeThis <http://goo.gl/uKir6>") | 82 "Please use var namesLikeThis <https://goo.gl/eQiXVW>") |
83 | 83 |
84 def _GetErrorHighlight(self, start, length): | 84 def _GetErrorHighlight(self, start, length): |
85 """Takes a start position and a length, and produces a row of '^'s to | 85 """Takes a start position and a length, and produces a row of '^'s to |
86 highlight the corresponding part of a string. | 86 highlight the corresponding part of a string. |
87 """ | 87 """ |
88 return start * ' ' + length * '^' | 88 return start * ' ' + length * '^' |
89 | 89 |
90 def RunChecks(self): | 90 def RunChecks(self): |
91 """Check for violations of the Chromium JavaScript style guide. See | 91 """Check for violations of the Chromium JavaScript style guide. See |
92 http://chromium.org/developers/web-development-style-guide#TOC-JavaScript | 92 http://chromium.org/developers/web-development-style-guide#TOC-JavaScript |
(...skipping 28 matching lines...) Expand all Loading... |
121 f.LocalPath()] + error_lines | 121 f.LocalPath()] + error_lines |
122 results.append(self.output_api.PresubmitError('\n'.join(error_lines))) | 122 results.append(self.output_api.PresubmitError('\n'.join(error_lines))) |
123 | 123 |
124 if results: | 124 if results: |
125 results.append(self.output_api.PresubmitNotifyResult( | 125 results.append(self.output_api.PresubmitNotifyResult( |
126 'See the JavaScript style guide at ' | 126 'See the JavaScript style guide at ' |
127 'http://www.chromium.org/developers/web-development-style-guide' | 127 'http://www.chromium.org/developers/web-development-style-guide' |
128 '#TOC-JavaScript')) | 128 '#TOC-JavaScript')) |
129 | 129 |
130 return results | 130 return results |
OLD | NEW |