Revision: 366
http://sourceforge.net/p/javascriptlint/code/366
Author: matthiasmiller
Date: 2016-12-29 21:35:41 +0000 (Thu, 29 Dec 2016)
Log Message:
-----------
Warn about non-normalized numbers as object properties.
Modified Paths:
--------------
trunk/javascriptlint/lintwarnings.py
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2016-12-23 23:55:18 UTC (rev 365)
+++ trunk/javascriptlint/lintwarnings.py 2016-12-29 21:35:41 UTC (rev 366)
@@ -104,6 +104,7 @@
'function_name_mismatch': 'function name {fn_name} does not match property name {prop_name}',
'trailing_whitespace': 'trailing whitespace',
'e4x_deprecated': 'e4x is deprecated',
+ 'ambiguous_numeric_prop': 'numeric property should be normalized; use {normalized}',
}
errors = {
@@ -634,6 +635,20 @@
if not left.kind in (tok.VAR, tok.NAME):
raise LintWarning(left)
+@lookfor(tok.NUMBER)
+def ambiguous_numeric_prop(node):
+ if node.atom.startswith('0x'):
+ value = int(node.atom, 16)
+ else:
+ value = float(node.atom)
+ if value.is_integer():
+ value = int(value)
+
+ if (node.node_index == 0 and node.parent.kind == tok.COLON) or \
+ (node.node_index == 1 and node.parent.kind == tok.LB):
+ if str(value) != node.atom:
+ raise LintWarning(node, normalized=str(value))
+
@lookfor(tok.FUNCTION)
def misplaced_function(node):
# Ignore function statements.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|