[javascriptlint-commit] SF.net SVN: javascriptlint:[351] trunk
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2014-10-27 19:12:00
|
Revision: 351
http://sourceforge.net/p/javascriptlint/code/351
Author: matthiasmiller
Date: 2014-10-27 19:11:53 +0000 (Mon, 27 Oct 2014)
Log Message:
-----------
Fix incorrect warning about unreachable loop condition.
Modified Paths:
--------------
trunk/javascriptlint/warnings.py
Added Paths:
-----------
trunk/tests/bugs/unreachable_loop_condition.js
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2014-02-10 23:48:14 UTC (rev 350)
+++ trunk/javascriptlint/warnings.py 2014-10-27 19:11:53 UTC (rev 351)
@@ -265,6 +265,14 @@
return exit_points
+def _loop_has_unreachable_condition(node):
+ for exit_point in _get_exit_points(node):
+ if exit_point is None:
+ return False
+ if exit_point.kind == tok.CONTINUE:
+ return False
+ return True
+
@lookfor((tok.EQOP, op.EQ))
def comparison_type_conv(node):
for kid in node.kids:
@@ -493,14 +501,14 @@
if preamble.kind == tok.RESERVED:
pre, condition, post = preamble.kids
if post:
- if not None in _get_exit_points(code):
+ if _loop_has_unreachable_condition(code):
raise LintWarning(post)
@lookfor(tok.DO)
def unreachable_code__(node):
# Warn if the do..while loop always exits.
code, condition = node.kids
- if not None in _get_exit_points(code):
+ if _loop_has_unreachable_condition(code):
raise LintWarning(condition)
#TODO: @lookfor(tok.IF)
Added: trunk/tests/bugs/unreachable_loop_condition.js
===================================================================
--- trunk/tests/bugs/unreachable_loop_condition.js (rev 0)
+++ trunk/tests/bugs/unreachable_loop_condition.js 2014-10-27 19:11:53 UTC (rev 351)
@@ -0,0 +1,36 @@
+function unreachable_loop_condition(skip) {
+ /* continue will run the condition.
+ */
+ for (var i = 0; i < 10; i++) {
+ if (skip)
+ continue;
+ break;
+ }
+
+ for (i = 0; i < 10; i++) { /*warning:unreachable_code*/
+ if (skip)
+ return;
+ break;
+ }
+
+
+ /* test with do..while
+ */
+ i = 0;
+ do {
+ i += 1;
+ if (skip)
+ continue;
+ break;
+ } while(i < 10);
+
+ i = 0;
+ do {
+ i += 1;
+ if (skip)
+ return;
+ break;
+ } while(i < 10); /*warning:unreachable_code*/
+
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|