Skip to content

Commit 021d31a

Browse files
committed
Code review: format and api-breakages
1 parent 7c46e82 commit 021d31a

File tree

3 files changed

+54
-47
lines changed

3 files changed

+54
-47
lines changed

Sources/SwiftFormat/Rules/OrderedImports.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ public final class OrderedImports: SyntaxFormatRule {
5757
testableImports = formatImports(testableImports)
5858
formatCodeblocks(&codeBlocks)
5959

60-
let joined = joinLines(fileHeader, regularImports, declImports, implementationOnlyImports, testableImports, codeBlocks)
60+
let joined = joinLines(
61+
fileHeader,
62+
regularImports,
63+
declImports,
64+
implementationOnlyImports,
65+
testableImports,
66+
codeBlocks
67+
)
6168
formattedLines.append(contentsOf: joined)
6269

6370
regularImports = []

Tests/SwiftFormatTests/Rules/OrderedImportsTests.swift

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -103,51 +103,50 @@ final class OrderedImportsTests: LintOrFormatRuleTestCase {
103103
]
104104
)
105105
}
106-
107-
func testImportsWithAttributes() {
108-
assertFormatting(
109-
OrderedImports.self,
110-
input: """
111-
import Foundation
112-
1️⃣@preconcurrency import AVFoundation
113-
114-
@preconcurrency @_implementationOnly import InternalModuleC
115-
116-
2️⃣@_implementationOnly import InternalModuleA
117-
118-
3️⃣import Core
119-
120-
@testable @preconcurrency import TestServiceB
121-
4️⃣@preconcurrency @testable import TestServiceA
122-
123-
5️⃣@_implementationOnly @preconcurrency import InternalModuleB
124-
125-
let a = 3
126-
""",
127-
expected: """
128-
@preconcurrency import AVFoundation
129-
import Core
130-
import Foundation
131-
132-
@_implementationOnly import InternalModuleA
133-
@_implementationOnly @preconcurrency import InternalModuleB
134-
@preconcurrency @_implementationOnly import InternalModuleC
135-
136-
@preconcurrency @testable import TestServiceA
137-
@testable @preconcurrency import TestServiceB
138-
139-
let a = 3
140-
""",
141-
findings: [
142-
FindingSpec("1️⃣", message: "sort import statements lexicographically"),
143-
FindingSpec("2️⃣", message: "sort import statements lexicographically"),
144-
FindingSpec("3️⃣", message: "place regular imports before implementationOnly imports"),
145-
FindingSpec("4️⃣", message: "sort import statements lexicographically"),
146-
FindingSpec("5️⃣", message: "place implementationOnly imports before testable imports")
147-
]
148-
)
149-
}
150106

107+
func testImportsWithAttributes() {
108+
assertFormatting(
109+
OrderedImports.self,
110+
input: """
111+
import Foundation
112+
1️⃣@preconcurrency import AVFoundation
113+
114+
@preconcurrency @_implementationOnly import InternalModuleC
115+
116+
2️⃣@_implementationOnly import InternalModuleA
117+
118+
3️⃣import Core
119+
120+
@testable @preconcurrency import TestServiceB
121+
4️⃣@preconcurrency @testable import TestServiceA
122+
123+
5️⃣@_implementationOnly @preconcurrency import InternalModuleB
124+
125+
let a = 3
126+
""",
127+
expected: """
128+
@preconcurrency import AVFoundation
129+
import Core
130+
import Foundation
131+
132+
@_implementationOnly import InternalModuleA
133+
@_implementationOnly @preconcurrency import InternalModuleB
134+
@preconcurrency @_implementationOnly import InternalModuleC
135+
136+
@preconcurrency @testable import TestServiceA
137+
@testable @preconcurrency import TestServiceB
138+
139+
let a = 3
140+
""",
141+
findings: [
142+
FindingSpec("1️⃣", message: "sort import statements lexicographically"),
143+
FindingSpec("2️⃣", message: "sort import statements lexicographically"),
144+
FindingSpec("3️⃣", message: "place regular imports before implementationOnly imports"),
145+
FindingSpec("4️⃣", message: "sort import statements lexicographically"),
146+
FindingSpec("5️⃣", message: "place implementationOnly imports before testable imports"),
147+
]
148+
)
149+
}
151150

152151
func testImportsOrderWithDocComment() {
153152
assertFormatting(
@@ -198,7 +197,7 @@ final class OrderedImportsTests: LintOrFormatRuleTestCase {
198197
import UIKit
199198
200199
import func Darwin.C.isatty
201-
200+
202201
@_implementationOnly import InternalModuleA
203202
@preconcurrency @_implementationOnly import InternalModuleB
204203
@@ -211,7 +210,7 @@ final class OrderedImportsTests: LintOrFormatRuleTestCase {
211210
import UIKit
212211
213212
import func Darwin.C.isatty
214-
213+
215214
@_implementationOnly import InternalModuleA
216215
@preconcurrency @_implementationOnly import InternalModuleB
217216

api-breakages.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ API breakage: func Configuration.MultilineStringReflowBehavior.hash(into:) has b
1818
API breakage: func Configuration.MultilineStringReflowBehavior.encode(to:) has been removed
1919
API breakage: var Configuration.MultilineStringReflowBehavior.hashValue has been removed
2020
API breakage: constructor Configuration.MultilineStringReflowBehavior.init(from:) has been removed
21+
API breakage: enum LineType.implementationOnlyImport has been added as a new enum case

0 commit comments

Comments
 (0)