Unneeded Break

ID

swift.unneeded_break

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Swift

Tags

code-smell, switch

Description

Reports a break at the end of a switch case body when the body has other statements. Swift’s switch does not fall through (unlike C / Java), so the trailing break is redundant.

A case body whose <em>only</em> statement is break is left alone — it is the idiomatic way to declare an empty case.

switch x {
case 0:
    name = "zero"
    break                                 // FLAW
case 1:
    return "one"                          // OK
default:
    break                                 // OK — only statement, intentional no-op
}

Rationale

The trailing break adds noise that suggests the author expected C / Java fall-through semantics. Removing it makes the intent clear.

Remediation

Delete the trailing break:

switch x {
case 0:
    name = "zero"
case 1:
    name = "one"
default:
    name = "many"
}