From 017e3a156e5e097fcffc0f8812afa5e4213258e1 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sun, 24 Oct 2010 21:30:26 -0400 Subject: [PATCH] Removing breaks from the last switch case, and just disabling the lint warning instead. --- extras/jsl.conf | 2 +- lib/lexer.js | 2 -- lib/nodes.js | 6 ++++-- src/nodes.coffee | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/extras/jsl.conf b/extras/jsl.conf index fb41a617..94e3e86c 100644 --- a/extras/jsl.conf +++ b/extras/jsl.conf @@ -11,7 +11,7 @@ -comma_separated_stmts # multiple statements separated by commas (use semicolons?) +unreachable_code # unreachable code +missing_break # missing break statement -+missing_break_for_last_case # missing break statement for last case in switch +-missing_break_for_last_case # missing break statement for last case in switch -comparison_type_conv # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==) -inc_dec_within_stmt # increment (++) and decrement (--) operators used as part of greater statement +useless_void # use of the void type may be unnecessary (void is always undefined) diff --git a/lib/lexer.js b/lib/lexer.js index aa9056a4..17733496 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -135,7 +135,6 @@ break; default: return 0; - break; } this.line += count(string, '\n'); return string.length; @@ -378,7 +377,6 @@ break; case '::': prev[0] = 'INDEX_PROTO'; - break; } } } diff --git a/lib/nodes.js b/lib/nodes.js index 9d20ddc5..4c19f07a 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1596,7 +1596,6 @@ return '--'; default: return pvar < 0 ? ' -= ' + pvar.slice(1) : ' += ' + pvar; - break; } })(); } @@ -1666,6 +1665,9 @@ code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n"); } code += block.compile(o, LEVEL_TOP) + '\n'; + if (i === this.cases.length - 1 && !this.otherwise) { + break; + } _ref5 = block.expressions; for (_j = _ref5.length - 1; _j >= 0; _j--) { expr = _ref5[_j]; @@ -1678,7 +1680,7 @@ } } if (this.otherwise) { - code += idt1 + ("default:\n" + (this.otherwise.compile(o, LEVEL_TOP)) + "\n" + idt2 + "break;\n"); + code += idt1 + ("default:\n" + (this.otherwise.compile(o, LEVEL_TOP)) + "\n"); } return code + this.tab + '}'; }; diff --git a/src/nodes.coffee b/src/nodes.coffee index 45393232..ad6e7b43 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1367,10 +1367,11 @@ exports.Switch = class Switch extends Base cond = cond.invert() unless @subject code += idt1 + "case #{ cond.compile o, LEVEL_PAREN }:\n" code += block.compile(o, LEVEL_TOP) + '\n' + break if i is @cases.length - 1 and not @otherwise for expr in block.expressions by -1 when expr not instanceof Comment code += idt2 + 'break;\n' unless expr instanceof Return break - code += idt1 + "default:\n#{ @otherwise.compile o, LEVEL_TOP }\n#{idt2}break;\n" if @otherwise + code += idt1 + "default:\n#{ @otherwise.compile o, LEVEL_TOP }\n" if @otherwise code + @tab + '}' #### If