diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e3ecddb..93f7a183c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,10 @@ #### Enhancements -* None. +* Speed up Identical Operands rule by using syntaxmap instead of + regular expressions. + [PaulTaykalo](https://github.com/PaulTaykalo) + [#2918](https://github.com/realm/SwiftLint/issues/2918) #### Bug Fixes diff --git a/Rules.md b/Rules.md index 48120822c..d7600cd04 100644 --- a/Rules.md +++ b/Rules.md @@ -9671,6 +9671,10 @@ expect("foo") == "foo" ↓$0 == $0 ``` +```swift +↓a?.b == a?.b +``` + ```swift ↓1 != 1 ``` @@ -9691,6 +9695,10 @@ expect("foo") == "foo" ↓$0 != $0 ``` +```swift +↓a?.b != a?.b +``` + ```swift ↓1 === 1 ``` @@ -9711,6 +9719,10 @@ expect("foo") == "foo" ↓$0 === $0 ``` +```swift +↓a?.b === a?.b +``` + ```swift ↓1 !== 1 ``` @@ -9731,6 +9743,10 @@ expect("foo") == "foo" ↓$0 !== $0 ``` +```swift +↓a?.b !== a?.b +``` + ```swift ↓1 > 1 ``` @@ -9751,6 +9767,10 @@ expect("foo") == "foo" ↓$0 > $0 ``` +```swift +↓a?.b > a?.b +``` + ```swift ↓1 >= 1 ``` @@ -9771,6 +9791,10 @@ expect("foo") == "foo" ↓$0 >= $0 ``` +```swift +↓a?.b >= a?.b +``` + ```swift ↓1 < 1 ``` @@ -9791,6 +9815,10 @@ expect("foo") == "foo" ↓$0 < $0 ``` +```swift +↓a?.b < a?.b +``` + ```swift ↓1 <= 1 ``` @@ -9811,6 +9839,10 @@ expect("foo") == "foo" ↓$0 <= $0 ``` +```swift +↓a?.b <= a?.b +``` + diff --git a/Source/SwiftLintFramework/Rules/Lint/IdenticalOperandsRule.swift b/Source/SwiftLintFramework/Rules/Lint/IdenticalOperandsRule.swift index 8930f9ed6..c2b2a99d0 100644 --- a/Source/SwiftLintFramework/Rules/Lint/IdenticalOperandsRule.swift +++ b/Source/SwiftLintFramework/Rules/Lint/IdenticalOperandsRule.swift @@ -46,7 +46,8 @@ public struct IdenticalOperandsRule: ConfigurationProviderRule, OptInRule, Autom "↓foo \(operation) foo", "↓foo.aProperty \(operation) foo.aProperty", "↓self.aProperty \(operation) self.aProperty", - "↓$0 \(operation) $0" + "↓$0 \(operation) $0", + "↓a?.b \(operation) a?.b" ] } ) @@ -103,14 +104,14 @@ public struct IdenticalOperandsRule: ConfigurationProviderRule, OptInRule, Autom } // Make sure both operands have same token types - guard zip(leftOperand.tokens, rightOperand.tokens).allSatisfy({ $0.0.type == $0.1.type }) else { + guard leftOperand.tokens.map({ $0.type }) == rightOperand.tokens.map({ $0.type }) else { return nil } - // Make sure that every part of the operand part is equal to previous on - guard zip(leftOperand.tokens, rightOperand.tokens).allSatisfy({ - contents.subStringWithSyntaxToken($0.0) == contents.subStringWithSyntaxToken($0.1) }) else { - return nil + // Make sure that every part of the operand part is equal to previous one + guard leftOperand.tokens.map(contents.subStringWithSyntaxToken) == + rightOperand.tokens.map(contents.subStringWithSyntaxToken) else { + return nil } guard let leftmostToken = leftOperand.tokens.first else {