Skip to content

Commit

Permalink
Change zip.allSatisfy to map ==
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulTaykalo committed Oct 25, 2019
1 parent b996e0c commit 1db3eb7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -9671,6 +9671,10 @@ expect("foo") == "foo"
↓$0 == $0
```

```swift
↓a?.b == a?.b
```

```swift
↓1 != 1
```
Expand All @@ -9691,6 +9695,10 @@ expect("foo") == "foo"
↓$0 != $0
```

```swift
↓a?.b != a?.b
```

```swift
↓1 === 1
```
Expand All @@ -9711,6 +9719,10 @@ expect("foo") == "foo"
↓$0 === $0
```

```swift
↓a?.b === a?.b
```

```swift
↓1 !== 1
```
Expand All @@ -9731,6 +9743,10 @@ expect("foo") == "foo"
↓$0 !== $0
```

```swift
↓a?.b !== a?.b
```

```swift
↓1 > 1
```
Expand All @@ -9751,6 +9767,10 @@ expect("foo") == "foo"
↓$0 > $0
```

```swift
↓a?.b > a?.b
```

```swift
↓1 >= 1
```
Expand All @@ -9771,6 +9791,10 @@ expect("foo") == "foo"
↓$0 >= $0
```

```swift
↓a?.b >= a?.b
```

```swift
↓1 < 1
```
Expand All @@ -9791,6 +9815,10 @@ expect("foo") == "foo"
↓$0 < $0
```

```swift
↓a?.b < a?.b
```

```swift
↓1 <= 1
```
Expand All @@ -9811,6 +9839,10 @@ expect("foo") == "foo"
↓$0 <= $0
```

```swift
↓a?.b <= a?.b
```

</details>


Expand Down
13 changes: 7 additions & 6 deletions Source/SwiftLintFramework/Rules/Lint/IdenticalOperandsRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1db3eb7

Please sign in to comment.