noFallthroughSwitchClause
Summary
Section titled Summary- Rule available since:
v1.0.0
- Diagnostic Category:
lint/suspicious/noFallthroughSwitchClause
- This rule is recommended, which means is enabled by default.
- This rule doesn’t have a fix.
- The default severity of this rule is error.
- Sources:
- Same as
no-fallthrough
- Same as
Description
Section titled DescriptionDisallow fallthrough of switch
clauses.
Switch clauses in switch
statements fall through by default.
This can lead to unexpected behavior when forgotten.
The rule doesn’t take
process.exit()
in consideration.
Examples
Section titled ExamplesInvalid
Section titled Invalidswitch (bar) { case 0: a(); case 1: b();}
code-block.js:2:2 lint/suspicious/noFallthroughSwitchClause ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This case is falling through to the next case.
1 │ switch (bar) {
> 2 │ case 0:
│ ^^^^^^^
> 3 │ a();
│ ^^^^
4 │ case 1:
5 │ b();
ℹ Add a break
or return
statement to the end of this case to prevent fallthrough.
Valid
Section titled Validswitch (foo) { case 1: case 2: doSomething(); break; case 3: { if (cond) { break; } else { break; } } case 4: doSomething();}
How to configure
Section titled How to configure{ "linter": { "rules": { "suspicious": { "noFallthroughSwitchClause": "error" } } }}