Unused Optional Binding

Prefer != nil over let _ =

  • Identifier: unused_optional_binding
  • Enabled by default: Yes
  • Supports autocorrection: No
  • Kind: style
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration: warning, ignore_optional_try: false

Non Triggering Examples

if let bar = Foo.optionalValue {
}

if let (_, second) = getOptionalTuple() {
}

if let (_, asd, _) = getOptionalTuple(), let bar = Foo.optionalValue {
}

if foo() { let _ = bar() }

if foo() { _ = bar() }

if case .some(_) = self {}
if let point = state.find({ _ in true }) {}

Triggering Examples

if let _ = Foo.optionalValue {
}

if let a = Foo.optionalValue, let _ = Foo.optionalValue2 {
}

guard let a = Foo.optionalValue, let _ = Foo.optionalValue2 {
}

if let (first, second) = getOptionalTuple(), let _ = Foo.optionalValue {
}

if let (first, _) = getOptionalTuple(), let _ = Foo.optionalValue {
}

if let (_, second) = getOptionalTuple(), let _ = Foo.optionalValue {
}

if let (_, _, _) = getOptionalTuple(), let bar = Foo.optionalValue {
}

func foo() {
if let _ = bar {
}

if case .some(let _) = self {}