org.sonar.l10n.javascript.rules.javascript.NonEmptyCaseWithoutBreak.html Maven / Gradle / Ivy
When the last statement of a switch-clause is not a break statement, the control flow "falls" into the next switch-clause.
Whilst this is sometimes intentional, it is often a mistake which could lead to some unexpected behaviors.
This rule doesn't apply to empty switch-clauses. Indeed those empty switch-clauses allow to specify the same behavior to a group of cases.
The following code snippet illustrates this rule:
switch (param) {
case 0: // Compliant
case 1: // Compliant
break;
case 2: // Compliant
return;
case 3: // Compliant
throw new Error();
case 4: // Non-Compliant
doSomething();
default: // Compliant
doSomethingElse();
}