[javascriptlint-commit] SF.net SVN: javascriptlint:[228] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2008-08-28 00:14:17
|
Revision: 228 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=228&view=rev Author: matthiasmiller Date: 2008-08-28 00:14:15 +0000 (Thu, 28 Aug 2008) Log Message: ----------- unreachable_code: check for unreachable conditions in for loops and do..while loops Modified Paths: -------------- trunk/pyjsl/warnings.py trunk/tests/warnings/missing_break.js trunk/tests/warnings/unreachable_code.js Modified: trunk/pyjsl/warnings.py =================================================================== --- trunk/pyjsl/warnings.py 2008-08-28 00:02:50 UTC (rev 227) +++ trunk/pyjsl/warnings.py 2008-08-28 00:14:15 UTC (rev 228) @@ -382,6 +382,23 @@ if not sibling.kind in (tok.VAR, tok.FUNCTION): raise LintWarning, sibling +@lookfor(tok.FOR) +def unreachable_code_(node): + # Warn if the for loop always exits. + preamble, code = node.kids + if preamble.kind == tok.RESERVED: + pre, condition, post = preamble.kids + if post: + if not None in _get_exit_points(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): + raise LintWarning, condition + #TODO: @lookfor(tok.IF) def meaningless_block(node): condition, if_, else_ = node.kids Modified: trunk/tests/warnings/missing_break.js =================================================================== --- trunk/tests/warnings/missing_break.js 2008-08-28 00:02:50 UTC (rev 227) +++ trunk/tests/warnings/missing_break.js 2008-08-28 00:14:15 UTC (rev 228) @@ -94,7 +94,7 @@ case 9: /* test a break inside a loop */ - for (i = 0; i < 100; i++) { + for (;;) { break; } Modified: trunk/tests/warnings/unreachable_code.js =================================================================== --- trunk/tests/warnings/unreachable_code.js 2008-08-28 00:02:50 UTC (rev 227) +++ trunk/tests/warnings/unreachable_code.js 2008-08-28 00:14:15 UTC (rev 228) @@ -38,4 +38,27 @@ return 42; } } + + /* test unreachable statements in for loops */ + for (i = 0; i < 10; i++) { /*warning:unreachable_code*/ + if (i) + break; + else + return; + } + for (i = 0; i < 10; ) { + if (i) + break; + else + return; + } + + /* test unreachable statements in do..while loops. */ + do { + if (i) + break; + else + return; + } while (i); /*warning:unreachable_code*/ + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |