No Fallthrough Only

ID

swift.no_fallthrough_only

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Swift

Tags

reliability, suspicious-code

Description

Reports a switch case whose body is exactly one fallthrough statement. The case has no work of its own and behaves identically to extending the next case label’s pattern list.

switch state {
case .loading:
    fallthrough                       // FLAW
case .ready:
    refresh()
}

Rationale

A case that does nothing but fall through is almost always either a typo (the case body was forgotten) or a translation artefact from a C-style switch. The equivalent Swift idiom is a single case label with multiple patterns — that makes the "same body for both" intent explicit, prevents accidental drift if .ready later changes behaviour, and avoids relying on the order of cases.

Remediation

Collapse the patterns into a single case label:

switch state {
case .loading, .ready:
    refresh()
}

If the intent was actually to run additional code before falling through, add a real statement before the fallthrough — the rule only fires when the case body is a lone fallthrough.