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

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

Issue 2913453002: js_checker.py: Replace custom WrapperTypeCheck with ESLint's no-new-wrappers. (Closed)
Patch Set: 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 | « tools/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import js_checker 6 import js_checker
7 from os import path as os_path 7 from os import path as os_path
8 import re 8 import re
9 from sys import path as sys_path 9 from sys import path as sys_path
10 import test_util 10 import test_util
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 260
261 def testPolymerLocalIdPasses(self): 261 def testPolymerLocalIdPasses(self):
262 lines = [ 262 lines = [
263 "this.$.id", 263 "this.$.id",
264 "this.$.localId", 264 "this.$.localId",
265 "this.$['fancy-id']", 265 "this.$['fancy-id']",
266 ] 266 ]
267 for line in lines: 267 for line in lines:
268 self.ShouldPassPolymerLocalIdCheck(line) 268 self.ShouldPassPolymerLocalIdCheck(line)
269 269
270 def ShouldFailWrapperTypeCheck(self, line):
Dan Beam 2017/05/30 16:16:20 can we leave these? i know there's likely tests f
dpapad 2017/05/31 22:30:20 Added equivalent smoke tests in js_checker_eslint_
271 """Checks that the use of wrapper types (i.e. new Number(), @type {Number})
272 is a style error.
273 """
274 error = self.checker.WrapperTypeCheck(1, line)
275 self.assertNotEqual('', error,
276 msg='Should be flagged as style error: ' + line)
277 highlight = test_util.GetHighlight(line, error)
278 self.assertTrue(highlight in ('Boolean', 'Number', 'String'))
279
280 def ShouldPassWrapperTypeCheck(self, line):
281 """Checks that the wrapper type checker doesn't flag |line| as a style
282 error.
283 """
284 self.assertEqual('', self.checker.WrapperTypeCheck(1, line),
285 msg='Should not be flagged as style error: ' + line)
286
287 def testWrapperTypePasses(self):
288 lines = [
289 "/** @param {!ComplexType} */",
290 " * @type {Object}",
291 " * @param {Function=} opt_callback",
292 " * @param {} num Number of things to add to {blah}.",
293 " * @return {!print_preview.PageNumberSet}",
294 " /* @returns {Number} */", # Should be /** @return {Number} */
295 "* @param {!LocalStrings}"
296 " Your type of Boolean is false!",
297 " Then I parameterized a Number from my friend!",
298 " A String of Pearls",
299 " types.params.aBoolean.typeString(someNumber)",
300 ]
301 for line in lines:
302 self.ShouldPassWrapperTypeCheck(line)
303
304 def testWrapperTypeFails(self):
305 lines = [
306 " /**@type {String}*/(string)",
307 " * @param{Number=} opt_blah A number",
308 "/** @private @return {!Boolean} */",
309 " * @param {number|String}",
310 ]
311 for line in lines:
312 self.ShouldFailWrapperTypeCheck(line)
313
314 def ShouldFailVarNameCheck(self, line): 270 def ShouldFailVarNameCheck(self, line):
315 """Checks that var unix_hacker, $dollar are style errors.""" 271 """Checks that var unix_hacker, $dollar are style errors."""
316 error = self.checker.VarNameCheck(1, line) 272 error = self.checker.VarNameCheck(1, line)
317 self.assertNotEqual('', error, 273 self.assertNotEqual('', error,
318 msg='Should be flagged as style error: ' + line) 274 msg='Should be flagged as style error: ' + line)
319 highlight = test_util.GetHighlight(line, error) 275 highlight = test_util.GetHighlight(line, error)
320 self.assertFalse('var ' in highlight); 276 self.assertFalse('var ' in highlight);
321 277
322 def ShouldPassVarNameCheck(self, line): 278 def ShouldPassVarNameCheck(self, line):
323 """Checks that variableNamesLikeThis aren't style errors.""" 279 """Checks that variableNamesLikeThis aren't style errors."""
(...skipping 24 matching lines...) Expand all
348 " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in 304 " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in
349 # front of all these vars like 305 # front of all these vars like
350 "/** @const */ CONST_VAR = 1;", # this line has (<--). 306 "/** @const */ CONST_VAR = 1;", # this line has (<--).
351 ] 307 ]
352 for line in lines: 308 for line in lines:
353 self.ShouldPassVarNameCheck(line) 309 self.ShouldPassVarNameCheck(line)
354 310
355 311
356 if __name__ == '__main__': 312 if __name__ == '__main__':
357 unittest.main() 313 unittest.main()
OLDNEW
« no previous file with comments | « tools/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698