[javascriptlint-commit] SF.net SVN: javascriptlint:[284] trunk
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2009-10-22 11:53:04
|
Revision: 284
http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=284&view=rev
Author: matthiasmiller
Date: 2009-10-22 11:52:52 +0000 (Thu, 22 Oct 2009)
Log Message:
-----------
#1523100: Warn about unreached variable assignments.
Modified Paths:
--------------
trunk/javascriptlint/warnings.py
Added Paths:
-----------
trunk/tests/warnings/unreachable_code_2.js
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2009-10-22 11:43:08 UTC (rev 283)
+++ trunk/javascriptlint/warnings.py 2009-10-22 11:52:52 UTC (rev 284)
@@ -414,7 +414,16 @@
def unreachable_code(node):
if node.parent.kind == tok.LC:
for sibling in node.parent.kids[node.node_index+1:]:
- if not sibling.kind in (tok.VAR, tok.FUNCTION):
+ if sibling.kind == tok.VAR:
+ # Look for a variable assignment
+ for variable in sibling.kids:
+ value, = variable.kids
+ if value:
+ raise LintWarning, value
+ elif sibling.kind == tok.FUNCTION:
+ # Functions are always declared.
+ pass
+ else:
raise LintWarning, sibling
@lookfor(tok.FOR)
Added: trunk/tests/warnings/unreachable_code_2.js
===================================================================
--- trunk/tests/warnings/unreachable_code_2.js (rev 0)
+++ trunk/tests/warnings/unreachable_code_2.js 2009-10-22 11:52:52 UTC (rev 284)
@@ -0,0 +1,33 @@
+function unreachable_code_2() {
+
+ // Function declarations are never unreachable.
+ function scope_a()
+ {
+ return inner();
+ function inner() {
+ return 10;
+ }
+ }
+
+ // Variable declarations are never unreachable.
+ function scope_b()
+ {
+ return value;
+ var value;
+ }
+
+ // Variable assignments are, however.
+ function scope_c()
+ {
+ return value_a;
+ var value_a = 10; /*warning:unreachable_code*/
+ }
+
+ // Test multiple variables.
+ function scope_d()
+ {
+ return value_a;
+ var value_a, value_b = 10, value_c; /*warning:unreachable_code*/
+ }
+}
+
Property changes on: trunk/tests/warnings/unreachable_code_2.js
___________________________________________________________________
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|