[javascriptlint-commit] SF.net SVN: javascriptlint:[309] trunk
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2013-09-28 04:17:43
|
Revision: 309
http://sourceforge.net/p/javascriptlint/code/309
Author: matthiasmiller
Date: 2013-09-28 04:17:38 +0000 (Sat, 28 Sep 2013)
Log Message:
-----------
#39 require variable names in "for .. in" statements
Modified Paths:
--------------
trunk/javascriptlint/warnings.py
Added Paths:
-----------
trunk/tests/warnings/for_in_missing_identifier.js
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2013-09-28 04:08:31 UTC (rev 308)
+++ trunk/javascriptlint/warnings.py 2013-09-28 04:17:38 UTC (rev 309)
@@ -100,6 +100,7 @@
'anon_no_return_value': 'anonymous function does not always return value',
'unsupported_version': 'JavaScript {version} is not supported',
'incorrect_version': 'Expected /*jsl:content-type*/ control comment. The script was parsed with the wrong version.',
+ 'for_in_missing_identifier': 'for..in should have identifier on left side',
}
errors = {
@@ -587,6 +588,13 @@
if not node.fn_name:
_check_return_value(node)
+@lookfor((tok.FOR, op.FORIN))
+def for_in_missing_identifier(node):
+ assert node.kids[0].kind == tok.IN
+ left, right = node.kids[0].kids
+ if not left.kind in (tok.VAR, tok.NAME):
+ raise LintWarning, left
+
@lookfor()
def mismatch_ctrl_comments(node):
pass
Added: trunk/tests/warnings/for_in_missing_identifier.js
===================================================================
--- trunk/tests/warnings/for_in_missing_identifier.js (rev 0)
+++ trunk/tests/warnings/for_in_missing_identifier.js 2013-09-28 04:17:38 UTC (rev 309)
@@ -0,0 +1,12 @@
+/*jsl:option explicit*/
+function for_in_missing_identifier(o) {
+ var prop;
+ for (prop in o)
+ o[prop]++;
+
+ for (var prop2 in o)
+ o[prop2]++;
+
+ for (!prop in o) /*warning:for_in_missing_identifier*/
+ o[prop]++;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|