[javascriptlint-commit] SF.net SVN: javascriptlint:[213] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2008-08-23 23:14:12
|
Revision: 213 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=213&view=rev Author: matthiasmiller Date: 2008-08-23 23:14:10 +0000 (Sat, 23 Aug 2008) Log Message: ----------- first cut at implementing fallthru Modified Paths: -------------- trunk/pyjsl/lint.py trunk/pyjsl/warnings.py trunk/tests/warnings/missing_default_case.js Modified: trunk/pyjsl/lint.py =================================================================== --- trunk/pyjsl/lint.py 2008-08-23 22:32:48 UTC (rev 212) +++ trunk/pyjsl/lint.py 2008-08-23 23:14:10 UTC (rev 213) @@ -159,6 +159,29 @@ parse_errors.append((jsparse.NodePos(row, col), msg)) def report(node, errname): + if errname == 'missing_break': + # Find the end of the previous case/default and the beginning of + # the next case/default. + assert node.kind in (tok.CASE, tok.DEFAULT) + prevnode = node.parent.kids[node.node_index-1] + expectedfallthru = prevnode.end_pos(), node.start_pos() + elif errname == 'missing_break_for_last_case': + # Find the end of the current case/default and the end of the + # switch. + assert node.parent.kind == tok.LC + expectedfallthru = node.end_pos(), node.parent.end_pos() + else: + expectedfallthru = None + + if expectedfallthru: + start, end = expectedfallthru + for fallthru in fallthrus: + # Look for a fallthru between the end of the current case or + # default statement and the beginning of the next token. + if fallthru.start_pos() > start and fallthru.end_pos() < end: + fallthrus.remove(fallthru) + return + _report(node.start_pos(), errname, True) def _report(pos, errname, require_key): @@ -185,6 +208,7 @@ start_ignore = None declares = [] import_paths = [] + fallthrus = [] for comment in comments: cc = _parse_control_comment(comment) if cc: @@ -210,6 +234,8 @@ report(node, 'jsl_cc_not_understood') else: import_paths.append(parms) + elif keyword == 'fallthru': + fallthrus.append(node) else: if comment.opcode == 'c_comment': if '/*' in comment.atom or comment.atom.endswith('/'): @@ -244,6 +270,9 @@ if root: _lint_node(root, visitors) + for fallthru in fallthrus: + report(fallthru, 'invalid_fallthru') + # Process imports by copying global declarations into the universal scope. imports |= set(conf['declarations']) imports |= _globals Modified: trunk/pyjsl/warnings.py =================================================================== --- trunk/pyjsl/warnings.py 2008-08-23 22:32:48 UTC (rev 212) +++ trunk/pyjsl/warnings.py 2008-08-23 23:14:10 UTC (rev 213) @@ -65,6 +65,7 @@ 'missing_option_explicit': 'the "option explicit" control comment is missing', 'partial_option_explicit': 'the "option explicit" control comment, if used, must be in the first script tag', 'dup_option_explicit': 'duplicate "option explicit" control comment', + 'invalid_fallthru': 'unexpected "fallthru" control comment' } _visitors = [] Modified: trunk/tests/warnings/missing_default_case.js =================================================================== --- trunk/tests/warnings/missing_default_case.js 2008-08-23 22:32:48 UTC (rev 212) +++ trunk/tests/warnings/missing_default_case.js 2008-08-23 23:14:10 UTC (rev 213) @@ -8,10 +8,10 @@ return 1; } - /* ambivalence - allow fallthru but don't enforce it */ + /* ambivalence - fallthru is meaningless */ switch (i) { case 2: - /*jsl:fallthru*/ + /*jsl:fallthru*/ /*warning:invalid_fallthru*/ case 3: s += 1; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |