unneeded_break_in_switch - ApplebaumIan/BitbucketAPI GitHub Wiki

Unneeded Break in Switch

Avoid using unneeded break statements.

  • Identifier: unneeded_break_in_switch
  • Enabled by default: Enabled
  • Supports autocorrection: No
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 3.0.0
  • Default configuration: warning

Non Triggering Examples

switch foo {
case .bar:
    break
}
switch foo {
default:
    break
}
switch foo {
case .bar:
    for i in [0, 1, 2] { break }
}
switch foo {
case .bar:
    if true { break }
}
switch foo {
case .bar:
    something()
}

Triggering Examples

switch foo {
case .bar:
    something()
    ↓break
}
switch foo {
case .bar:
    something()
    ↓break // comment
}
switch foo {
default:
    something()
    ↓break
}
switch foo {
case .foo, .foo2 where condition:
    something()
    ↓break
}