pi-lens
Version:
Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo
64 lines (53 loc) • 1.27 kB
YAML
# Switch Non-Case Labels
# Detects non-case labels inside switch statements
id: switch-non-case-labels
name: Switch Statements Should Not Contain Non-Case Labels
severity: error
category: reliability
defect_class: correctness
inline_tier: blocking
language: java
message: "Non-case labels should not be used inside switch statements"
description: |
Using labels (other than case/default) inside switch statements is confusing
and can lead to unexpected control flow. This is also a MISRA C rule.
✅ FIX: Remove the label or restructure the code
```java
switch (value) {
case 1:
process();
break;
default:
handleDefault();
}
```
query: |
(switch_expression
body: (switch_block
(switch_block_statement_group
(labeled_statement
(identifier) ) )))
metavars:
- LABEL
- LABELED_STMT
tags:
- reliability
- misra
- java
- control-flow
examples:
bad: |
switch (x) {
case 1:
break;
myLabel: // BAD - non-case label in switch
doSomething();
}
good: |
switch (x) {
case 1:
break;
default:
break; // GOOD - only case/default labels
}
has_fix: false