pi-lens
Version:
Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo
62 lines (50 loc) • 1.21 kB
YAML
id: switch-case-termination-js
name: Switch Cases Should End With Terminating Statement
severity: error
category: reliability
defect_class: correctness
inline_tier: blocking
language: javascript
message: "Switch case should end with break, return, throw, or continue"
description: |
Switch cases that fall through to the next case cause bugs.
Each case should end with break, return, throw, or continue.
If fall-through is intentional, add a // fallthrough comment.
✅ FIX: Add terminating statement
```javascript
switch (x) {
case 1:
doSomething();
break; // GOOD
}
```
query: |
(switch_body
(switch_case) @CASE
.
[(switch_case) (switch_default)])
metavars:
- CASE
post_filter: no_terminating_statement
tags:
- reliability
- javascript
- bugs
examples:
bad: |
switch (x) {
case 1:
doSomething(); // BAD - falls through
case 2:
break;
}
good: |
switch (x) {
case 1:
return "one"; // GOOD - return terminates
case 2:
break;
}
has_fix: false