[javascriptlint-commit] SF.net SVN: javascriptlint:[370] trunk
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2016-12-29 22:10:21
|
Revision: 370
http://sourceforge.net/p/javascriptlint/code/370
Author: matthiasmiller
Date: 2016-12-29 22:10:19 +0000 (Thu, 29 Dec 2016)
Log Message:
-----------
Refactor property name functions into utility module.
Modified Paths:
--------------
trunk/javascriptlint/lintwarnings.py
Added Paths:
-----------
trunk/jsengine/js_util.py
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2016-12-29 21:57:52 UTC (rev 369)
+++ trunk/javascriptlint/lintwarnings.py 2016-12-29 22:10:19 UTC (rev 370)
@@ -19,6 +19,7 @@
import util
+from jsengine import js_util
from jsengine.parser import kind as tok
from jsengine.parser import op
@@ -636,44 +637,22 @@
if not left.kind in (tok.VAR, tok.NAME):
raise LintWarning(left)
-def _normalized_number(node):
- assert node.kind == tok.NUMBER
- if node.atom.startswith('0x'):
- value = int(node.atom, 16)
- else:
- value = float(node.atom)
- if value.is_integer():
- value = int(value)
- return str(value)
-
@lookfor(tok.NUMBER)
def ambiguous_numeric_prop(node):
- normalized = _normalized_number(node)
+ normalized = js_util.numeric_property_str(node)
if (node.node_index == 0 and node.parent.kind == tok.COLON) or \
(node.node_index == 1 and node.parent.kind == tok.LB):
if normalized != node.atom:
raise LintWarning(node, normalized=normalized)
-def _object_property(node):
- assert node.kind == tok.COLON
-
- left, right = node.kids
- while left.kind == tok.RP:
- left, = left.kids
- if left.kind == tok.NUMBER:
- return _normalized_number(left)
-
- assert left.kind in (tok.STRING, tok.NAME)
- return left.atom
-
@lookfor(tok.COLON)
def duplicate_property(node):
if not node.parent.kind == tok.RC:
return
- node_value = _object_property(node)
+ node_value = js_util.object_property_str(node)
for sibling in node.parent.kids[:node.node_index]:
- sibling_value = _object_property(sibling)
+ sibling_value = js_util.object_property_str(sibling)
if node_value == sibling_value:
raise LintWarning(node)
Added: trunk/jsengine/js_util.py
===================================================================
--- trunk/jsengine/js_util.py (rev 0)
+++ trunk/jsengine/js_util.py 2016-12-29 22:10:19 UTC (rev 370)
@@ -0,0 +1,25 @@
+# vim: ts=4 sw=4 expandtab
+from parser import kind as tok
+
+def numeric_property_str(node):
+ assert node.kind == tok.NUMBER
+ if node.atom.startswith('0x'):
+ value = int(node.atom, 16)
+ else:
+ value = float(node.atom)
+ if value.is_integer():
+ value = int(value)
+ return str(value)
+
+def object_property_str(node):
+ assert node.kind == tok.COLON
+
+ left, right = node.kids
+ while left.kind == tok.RP:
+ left, = left.kids
+ if left.kind == tok.NUMBER:
+ return numeric_property_str(left)
+
+ assert left.kind in (tok.STRING, tok.NAME)
+ return left.atom
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|