Empty Enum Arguments

Arguments can be omitted when matching enums with associated values if they are not used

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

Non Triggering Examples

switch foo {
case .bar: break
}
switch foo {
case .bar(let x): break
}
switch foo {
case let .bar(x): break
}
switch (foo, bar) {
case (_, _): break
}
switch foo {
case "bar".uppercased(): break
}
switch (foo, bar) {
case (_, _) where !something: break
}
switch foo {
case (let f as () -> String)?: break
}
switch foo {
case .bar(Baz()): break
}
switch foo {
case .bar(.init()): break
}
switch foo {
default: break
}
if case .bar = foo {
}
guard case .bar = foo else {
}
if foo == .bar() {}
guard foo == .bar() else { return }
if case .appStore = self.appInstaller, !UIDevice.isSimulator() {
    viewController.present(self, animated: false)
} else {
    UIApplication.shared.open(self.appInstaller.url)
}
let updatedUserNotificationSettings = deepLink.filter { nav in
    guard case .settings(.notifications(_, nil)) = nav else { return false }
    return true
}

Triggering Examples

switch foo {
case .bar(_): break
}
switch foo {
case .bar(): break
}
switch foo {
case .bar(_), .bar2(_): break
}
switch foo {
case .bar() where method() > 2: break
}
switch foo {
case .bar(.baz()): break
}
switch foo {
case .bar(.baz(_)): break
}
func example(foo: Foo) {
    switch foo {
    case .bar(_):
        break
    }
}
if case .bar(_) = foo {
}
guard case .bar(_) = foo else {
}
if case .bar() = foo {
}
guard case .bar() = foo else {
}
if case .appStore(_) = self.appInstaller, !UIDevice.isSimulator() {
    viewController.present(self, animated: false)
} else {
    UIApplication.shared.open(self.appInstaller.url)
}
let updatedUserNotificationSettings = deepLink.filter { nav in
    guard case .settings(.notifications(_, _)) = nav else { return false }
    return true
}