Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1333)

Side by Side Diff: tools/web_dev_style/js_checker.py

Issue 2907763004: js_checker.py: Replace custom GetElementByIdCheck with ESLint no-restricted-properties. (Closed)
Patch Set: Resolve conflicts. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « .eslintrc.js ('k') | tools/web_dev_style/js_checker_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 def EndJsDocCommentCheck(self, i, line): 45 def EndJsDocCommentCheck(self, i, line):
46 msg = 'End JSDoc comments with */ instead of **/' 46 msg = 'End JSDoc comments with */ instead of **/'
47 def _check(regex): 47 def _check(regex):
48 return self.RegexCheck(i, line, regex, msg) 48 return self.RegexCheck(i, line, regex, msg)
49 return _check(r'^\s*(\*\*/)\s*$') or _check(r'/\*\* @[a-zA-Z]+.* (\*\*/)') 49 return _check(r'^\s*(\*\*/)\s*$') or _check(r'/\*\* @[a-zA-Z]+.* (\*\*/)')
50 50
51 def ExtraDotInGenericCheck(self, i, line): 51 def ExtraDotInGenericCheck(self, i, line):
52 return self.RegexCheck(i, line, r"((?:Array|Object|Promise)\.<)", 52 return self.RegexCheck(i, line, r"((?:Array|Object|Promise)\.<)",
53 "Don't use a dot after generics (Object.<T> should be Object<T>).") 53 "Don't use a dot after generics (Object.<T> should be Object<T>).")
54 54
55 def GetElementByIdCheck(self, i, line):
56 """Checks for use of 'document.getElementById' instead of '$'."""
57 return self.RegexCheck(i, line, r"(document\.getElementById)\('",
58 "Use $('id') or getSVGElement('id') from chrome://resources/js/util.js "
59 "instead of document.getElementById('id')")
60
61 def InheritDocCheck(self, i, line): 55 def InheritDocCheck(self, i, line):
62 """Checks for use of '@inheritDoc' instead of '@override'.""" 56 """Checks for use of '@inheritDoc' instead of '@override'."""
63 return self.RegexCheck(i, line, r"\* (@inheritDoc)", 57 return self.RegexCheck(i, line, r"\* (@inheritDoc)",
64 "@inheritDoc is deprecated, use @override instead") 58 "@inheritDoc is deprecated, use @override instead")
65 59
66 def PolymerLocalIdCheck(self, i, line): 60 def PolymerLocalIdCheck(self, i, line):
67 """Checks for use of element.$.localId.""" 61 """Checks for use of element.$.localId."""
68 return self.RegexCheck(i, line, r"(?<!this)(\.\$)[\[\.]", 62 return self.RegexCheck(i, line, r"(?<!this)(\.\$)[\[\.]",
69 "Please only use this.$.localId, not element.$.localId") 63 "Please only use this.$.localId, not element.$.localId")
70 64
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 results += self.RunEsLintChecks(affected_js_files) 128 results += self.RunEsLintChecks(affected_js_files)
135 129
136 for f in affected_js_files: 130 for f in affected_js_files:
137 error_lines = [] 131 error_lines = []
138 132
139 for i, line in enumerate(f.NewContents(), start=1): 133 for i, line in enumerate(f.NewContents(), start=1):
140 error_lines += filter(None, [ 134 error_lines += filter(None, [
141 self.ChromeSendCheck(i, line), 135 self.ChromeSendCheck(i, line),
142 self.CommentIfAndIncludeCheck(i, line), 136 self.CommentIfAndIncludeCheck(i, line),
143 self.ConstCheck(i, line), 137 self.ConstCheck(i, line),
144 self.GetElementByIdCheck(i, line),
145 self.EndJsDocCommentCheck(i, line), 138 self.EndJsDocCommentCheck(i, line),
146 self.ExtraDotInGenericCheck(i, line), 139 self.ExtraDotInGenericCheck(i, line),
147 self.InheritDocCheck(i, line), 140 self.InheritDocCheck(i, line),
148 self.PolymerLocalIdCheck(i, line), 141 self.PolymerLocalIdCheck(i, line),
149 self.WrapperTypeCheck(i, line), 142 self.WrapperTypeCheck(i, line),
150 self.VarNameCheck(i, line), 143 self.VarNameCheck(i, line),
151 ]) 144 ])
152 145
153 if error_lines: 146 if error_lines:
154 error_lines = [ 147 error_lines = [
155 'Found JavaScript style violations in %s:' % 148 'Found JavaScript style violations in %s:' %
156 f.LocalPath()] + error_lines 149 f.LocalPath()] + error_lines
157 results.append(self.output_api.PresubmitError('\n'.join(error_lines))) 150 results.append(self.output_api.PresubmitError('\n'.join(error_lines)))
158 151
159 if results: 152 if results:
160 results.append(self.output_api.PresubmitNotifyResult( 153 results.append(self.output_api.PresubmitNotifyResult(
161 'See the JavaScript style guide at ' 154 'See the JavaScript style guide at '
162 'https://chromium.googlesource.com/chromium/src/+/master/styleguide/we b/web.md#JavaScript')) 155 'https://chromium.googlesource.com/chromium/src/+/master/styleguide/we b/web.md#JavaScript'))
163 156
164 return results 157 return results
OLDNEW
« no previous file with comments | « .eslintrc.js ('k') | tools/web_dev_style/js_checker_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698