Pattern Matching Keywords

Combine multiple pattern matching bindings by moving binding keywords out of tuples and associated values in enum cases to reduce visual noise.

  • Identifier: pattern_matching_keywords
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

switch foo {
    default: break
}
switch foo {
    case 1: break
}
switch foo {
    case bar: break
}
switch foo {
    case let (x, y): break
}
switch foo {
    case .foo(let x): break
}
switch foo {
    case let .foo(x, y): break
}
switch foo {
    case .foo(let x), .bar(let x): break
}
switch foo {
    case .foo(let x, var y): break
}
switch foo {
    case var (x, y): break
}
switch foo {
    case .foo(var x): break
}
switch foo {
    case var .foo(x, y): break
}
switch foo {
    case (y, let x, z): break
}
switch foo {
    case (foo, let x): break
}
switch foo {
    case (foo, let x, let y): break
}
switch foo {
    case .foo(bar, let x): break
}
switch foo {
    case (let x, y): break
}
switch foo {
    case .foo(let x, y): break
}
switch foo {
    case (.foo(let x), y): break
}
switch foo {
    case let .foo(x, y), let .bar(x, y): break
}
switch foo {
    case var .foo(x, y), var .bar(x, y): break
}
switch foo {
    case let .foo(x, y), let .bar(x, y), let .baz(x, y): break
}
switch foo {
    case .foo(bar: let x, baz: var y): break
}
switch foo {
    case (.yamlParsing(var x), (.yamlParsing(var y), z)): break
}
switch foo {
    case (.foo(let x), (y, let z)): break
}
if case let (x, y) = foo {}
guard case let (x, y) = foo else { return }
while case let (x, y) = foo {}
for case let (x, y) in foos {}
if case (foo, let x) = value {}
guard case .foo(bar, let x) = value else { return }
do {} catch let Pattern.error(x, y) {}
do {} catch (foo, let x) {}

Triggering Examples

switch foo {
    case (let x, let y): break
}
switch foo {
    case (let x, let y, .foo): break
}
switch foo {
    case (let x, let y, _): break
}
switch foo {
    case (let x, let y, 1): break
}
switch foo {
    case (let x, let y, f()): break
}
switch foo {
    case (let x, let y, s.f()): break
}
switch foo {
    case (let x, let y, s.t): break
}
switch foo {
    case .foo(let x, let y): break
}
switch foo {
    case .foo(bar: let x, baz: let y): break
}
switch foo {
    case .foo(var x, var y): break
}
switch foo {
    case .foo(bar: var x, baz: var y): break
}
switch foo {
    case (.yamlParsing(let x), .yamlParsing(let y)): break
}
switch foo {
    case (.yamlParsing(var x), (.yamlParsing(var y), _)): break
}
switch foo {
    case ((let x, let y), z): break
}
switch foo {
    case .foo((let x, let y), z): break
}
switch foo {
    case (.foo(let x, let y), z): break
}
switch foo {
    case .foo(.bar(let x), .bar(let y)): break
}
switch foo {
    case .foo(.bar(let x), .bar(let y), .baz): break
}
switch foo {
    case .foo(let x, let y), .bar(let x, let y): break
}
switch foo {
    case .foo(var x, var y), .bar(var x, var y): break
}
if case (let x, let y) = foo {}
guard case (let x, let y) = foo else { return }
while case (let x, let y) = foo {}
for case (let x, let y) in foos {}
if case .foo(bar: let x, baz: let y) = value {}
do {} catch Pattern.error(let x, let y) {}
do {} catch (let x, let y) {}
do {} catch Foo.outer(.inner(let x), .inner(let y)) {}