Skip to content

Commit cae4d67

Browse files
committed
Add quick fix for sortTypealiases unhandled cases
1 parent 6f0d8db commit cae4d67

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Sources/ParsingHelpers.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,18 @@ extension Formatter {
22202220

22212221
guard !andTokenIndices.isEmpty else { return nil }
22222222

2223+
// Quick fix for types we don't support yet
2224+
let firstRange = tokens[equalsIndex ..< andTokenIndices[0]]
2225+
guard !firstRange.contains(where: {
2226+
["any", "[", "(", ":"].contains($0.string)
2227+
}), firstRange.filter({
2228+
$0 == .startOfScope("<")
2229+
}).count == firstRange.filter({
2230+
$0 == .endOfScope(">")
2231+
}).count else {
2232+
return nil
2233+
}
2234+
22232235
return (equalsIndex, andTokenIndices, type.range.upperBound)
22242236
}
22252237

Tests/Rules/SortTypealiasesTests.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,8 @@ class SortTypealiasesTests: XCTestCase {
177177
}
178178

179179
func testSortSingleLineTypealiasBeginningWithAny() {
180-
let input = """
181-
typealias Placeholders = any Foo & Bar & Quux & Baaz
182-
"""
183-
184-
let output = """
185-
typealias Placeholders = any Baaz & Bar & Foo & Quux
186-
"""
187-
188-
testFormatting(for: input, output, rule: .sortTypealiases)
180+
let input = "typealias Placeholders = any Bar & Foo"
181+
testFormatting(for: input, rule: .sortTypealiases)
189182
}
190183

191184
func testCollectionTypealiasWithArrayOfExistentialTypes() {
@@ -199,7 +192,7 @@ class SortTypealiasesTests: XCTestCase {
199192
}
200193

201194
func testCollectionTypealiasWithOptionalExistentialType() {
202-
let input = "public typealias Parameters = (any Hashable & Sendable)?"
195+
let input = "public typealias Parameters = (Hashable & Sendable)?"
203196
testFormatting(for: input, rule: .sortTypealiases)
204197
}
205198

0 commit comments

Comments
 (0)