Skip to content

Commit 26fd167

Browse files
committed
Extend supported prefersKeyPath functions
1 parent 93f56af commit 26fd167

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

Sources/Examples.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,8 +1128,10 @@ private struct Examples {
11281128
let preferKeyPath = """
11291129
```diff
11301130
- let barArray = fooArray.map { $0.bar }
1131-
11321131
+ let barArray = fooArray.map(\\.bar)
1132+
1133+
- let barArray = fooArray.compactMap { $0.optionalBar }
1134+
+ let barArray = fooArray.compactMap(\\.optionalBar)
11331135
```
11341136
"""
11351137

Sources/Rules.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5127,13 +5127,13 @@ public struct _FormatRules {
51275127
if parenthesized {
51285128
prevToken = formatter.last(.nonSpaceOrLinebreak, before: prevIndex) ?? prevToken
51295129
}
5130-
guard [.identifier("map"), .identifier("flatMap"),
5131-
.identifier("compactMap")].contains(prevToken),
5132-
let nextIndex = formatter.index(of: .nonSpaceOrLinebreak, after: i, if: {
5133-
$0 == .identifier("$0")
5134-
}),
5135-
let endIndex = formatter.endOfScope(at: i),
5136-
let lastIndex = formatter.index(of: .nonSpaceOrLinebreak, before: endIndex)
5130+
guard case let .identifier(name) = prevToken,
5131+
["map", "flatMap", "compactMap", "allSatisfy", "filter"].contains(name),
5132+
let nextIndex = formatter.index(of: .nonSpaceOrLinebreak, after: i, if: {
5133+
$0 == .identifier("$0")
5134+
}),
5135+
let endIndex = formatter.endOfScope(at: i),
5136+
let lastIndex = formatter.index(of: .nonSpaceOrLinebreak, before: endIndex)
51375137
else {
51385138
return
51395139
}

0 commit comments

Comments
 (0)