Yoda Condition

The constant literal should be placed on the right-hand side of the comparison operator

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

Non Triggering Examples

if foo == 42 {}
if foo <= 42.42 {}
guard foo >= 42 else { return }
guard foo != "str str" else { return }
while foo < 10 { }
while foo > 1 { }
while foo + 1 == 2 {}
if optionalValue?.property ?? 0 == 2 {}
if foo == nil {}
if flags & 1 == 1 {}

Triggering Examples

if 42 == foo {}
if 42.42 >= foo {}
guard 42 <= foo else { return }
guard "str str" != foo else { return }
while 10 > foo { }
while 1 < foo { }
if nil == foo {}
while 1 > i + 5 {}
if 200 <= i && i <= 299 || 600 <= i {}