Identical Operands

Comparing two identical operands is likely a mistake

  • Identifier: identical_operands
  • 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

1 == 2
foo == bar
prefixedFoo == foo
foo.aProperty == foo.anotherProperty
self.aProperty == self.anotherProperty
"1 == 1"
self.aProperty == aProperty
lhs.aProperty == rhs.aProperty
lhs.identifier == rhs.identifier
i == index
$0 == 0
keyValues?.count ?? 0 == 0
string == string.lowercased()
let num: Int? = 0
_ = num != nil && num == num?.byteSwapped
num == num!.byteSwapped
1    + 1 ==   1     +    2
f(  i :   2) ==   f (i: 3 )
1 != 2
foo != bar
prefixedFoo != foo
foo.aProperty != foo.anotherProperty
self.aProperty != self.anotherProperty
"1 != 1"
self.aProperty != aProperty
lhs.aProperty != rhs.aProperty
lhs.identifier != rhs.identifier
i != index
$0 != 0
keyValues?.count ?? 0 != 0
string != string.lowercased()
let num: Int? = 0
_ = num != nil && num != num?.byteSwapped
num != num!.byteSwapped
1    + 1 !=   1     +    2
f(  i :   2) !=   f (i: 3 )
1 === 2
foo === bar
prefixedFoo === foo
foo.aProperty === foo.anotherProperty
self.aProperty === self.anotherProperty
"1 === 1"
self.aProperty === aProperty
lhs.aProperty === rhs.aProperty
lhs.identifier === rhs.identifier
i === index
$0 === 0
keyValues?.count ?? 0 === 0
string === string.lowercased()
let num: Int? = 0
_ = num != nil && num === num?.byteSwapped
num === num!.byteSwapped
1    + 1 ===   1     +    2
f(  i :   2) ===   f (i: 3 )
1 !== 2
foo !== bar
prefixedFoo !== foo
foo.aProperty !== foo.anotherProperty
self.aProperty !== self.anotherProperty
"1 !== 1"
self.aProperty !== aProperty
lhs.aProperty !== rhs.aProperty
lhs.identifier !== rhs.identifier
i !== index
$0 !== 0
keyValues?.count ?? 0 !== 0
string !== string.lowercased()
let num: Int? = 0
_ = num != nil && num !== num?.byteSwapped
num !== num!.byteSwapped
1    + 1 !==   1     +    2
f(  i :   2) !==   f (i: 3 )
1 > 2
foo > bar
prefixedFoo > foo
foo.aProperty > foo.anotherProperty
self.aProperty > self.anotherProperty
"1 > 1"
self.aProperty > aProperty
lhs.aProperty > rhs.aProperty
lhs.identifier > rhs.identifier
i > index
$0 > 0
keyValues?.count ?? 0 > 0
string > string.lowercased()
let num: Int? = 0
_ = num != nil && num > num?.byteSwapped
num > num!.byteSwapped
1    + 1 >   1     +    2
f(  i :   2) >   f (i: 3 )
1 >= 2
foo >= bar
prefixedFoo >= foo
foo.aProperty >= foo.anotherProperty
self.aProperty >= self.anotherProperty
"1 >= 1"
self.aProperty >= aProperty
lhs.aProperty >= rhs.aProperty
lhs.identifier >= rhs.identifier
i >= index
$0 >= 0
keyValues?.count ?? 0 >= 0
string >= string.lowercased()
let num: Int? = 0
_ = num != nil && num >= num?.byteSwapped
num >= num!.byteSwapped
1    + 1 >=   1     +    2
f(  i :   2) >=   f (i: 3 )
1 < 2
foo < bar
prefixedFoo < foo
foo.aProperty < foo.anotherProperty
self.aProperty < self.anotherProperty
"1 < 1"
self.aProperty < aProperty
lhs.aProperty < rhs.aProperty
lhs.identifier < rhs.identifier
i < index
$0 < 0
keyValues?.count ?? 0 < 0
string < string.lowercased()
let num: Int? = 0
_ = num != nil && num < num?.byteSwapped
num < num!.byteSwapped
1    + 1 <   1     +    2
f(  i :   2) <   f (i: 3 )
1 <= 2
foo <= bar
prefixedFoo <= foo
foo.aProperty <= foo.anotherProperty
self.aProperty <= self.anotherProperty
"1 <= 1"
self.aProperty <= aProperty
lhs.aProperty <= rhs.aProperty
lhs.identifier <= rhs.identifier
i <= index
$0 <= 0
keyValues?.count ?? 0 <= 0
string <= string.lowercased()
let num: Int? = 0
_ = num != nil && num <= num?.byteSwapped
num <= num!.byteSwapped
1    + 1 <=   1     +    2
f(  i :   2) <=   f (i: 3 )
func evaluate(_ mode: CommandMode) -> Result<Options, CommandantError<CommandantError<()>>>
let array = Array<Array<Int>>()
guard Set(identifiers).count != identifiers.count else { return }
expect("foo") == "foo"
type(of: model).cachePrefix == cachePrefix
histogram[156].0 == 0x003B8D96 && histogram[156].1 == 1
[Wrapper(type: .three), Wrapper(type: .one)].sorted { "\($0.type)" > "\($1.type)"}
array.sorted { "\($0)" < "\($1)" }

Triggering Examples

1 == 1
foo == foo
foo.aProperty == foo.aProperty
self.aProperty == self.aProperty
$0 == $0
a?.b == a?.b
if (elem == elem) {}
XCTAssertTrue(s3 == s3)
if let tab = tabManager.selectedTab, tab.webView == tab.webView
1    + 1 ==   1     +    1
 f(  i :   2) ==   f (i: 
 2 )
1 != 1
foo != foo
foo.aProperty != foo.aProperty
self.aProperty != self.aProperty
$0 != $0
a?.b != a?.b
if (elem != elem) {}
XCTAssertTrue(s3 != s3)
if let tab = tabManager.selectedTab, tab.webView != tab.webView
1    + 1 !=   1     +    1
 f(  i :   2) !=   f (i: 
 2 )
1 === 1
foo === foo
foo.aProperty === foo.aProperty
self.aProperty === self.aProperty
$0 === $0
a?.b === a?.b
if (elem === elem) {}
XCTAssertTrue(s3 === s3)
if let tab = tabManager.selectedTab, tab.webView === tab.webView
1    + 1 ===   1     +    1
 f(  i :   2) ===   f (i: 
 2 )
1 !== 1
foo !== foo
foo.aProperty !== foo.aProperty
self.aProperty !== self.aProperty
$0 !== $0
a?.b !== a?.b
if (elem !== elem) {}
XCTAssertTrue(s3 !== s3)
if let tab = tabManager.selectedTab, tab.webView !== tab.webView
1    + 1 !==   1     +    1
 f(  i :   2) !==   f (i: 
 2 )
1 > 1
foo > foo
foo.aProperty > foo.aProperty
self.aProperty > self.aProperty
$0 > $0
a?.b > a?.b
if (elem > elem) {}
XCTAssertTrue(s3 > s3)
if let tab = tabManager.selectedTab, tab.webView > tab.webView
1    + 1 >   1     +    1
 f(  i :   2) >   f (i: 
 2 )
1 >= 1
foo >= foo
foo.aProperty >= foo.aProperty
self.aProperty >= self.aProperty
$0 >= $0
a?.b >= a?.b
if (elem >= elem) {}
XCTAssertTrue(s3 >= s3)
if let tab = tabManager.selectedTab, tab.webView >= tab.webView
1    + 1 >=   1     +    1
 f(  i :   2) >=   f (i: 
 2 )
1 < 1
foo < foo
foo.aProperty < foo.aProperty
self.aProperty < self.aProperty
$0 < $0
a?.b < a?.b
if (elem < elem) {}
XCTAssertTrue(s3 < s3)
if let tab = tabManager.selectedTab, tab.webView < tab.webView
1    + 1 <   1     +    1
 f(  i :   2) <   f (i: 
 2 )
1 <= 1
foo <= foo
foo.aProperty <= foo.aProperty
self.aProperty <= self.aProperty
$0 <= $0
a?.b <= a?.b
if (elem <= elem) {}
XCTAssertTrue(s3 <= s3)
if let tab = tabManager.selectedTab, tab.webView <= tab.webView
1    + 1 <=   1     +    1
 f(  i :   2) <=   f (i: 
 2 )
    return lhs.foo == lhs.foo &&
           lhs.bar == rhs.bar
    return lhs.foo == rhs.foo &&
           lhs.bar == lhs.bar