pi-lens
Version:
Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo
65 lines (53 loc) • 1.29 kB
YAML
id: switch-case-termination
name: Switch Cases Should End With Terminating Statement
severity: error
category: reliability
defect_class: correctness
inline_tier: blocking
language: typescript
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
```typescript
switch (x) {
case 1:
doSomething();
break; // GOOD
}
```
query: |
(switch_statement
body: (switch_body
(switch_case
consequence: (statement_block
(expression_statement) @LAST))
(switch_case) @NEXT))
metavars:
- LAST
- NEXT
post_filter: no_terminating_statement
tags:
- reliability
- typescript
- 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