Skip to content

Commit 03faf4e

Browse files
committed
Add newline after declarations
1 parent 2782139 commit 03faf4e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,16 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
10461046
position: position,
10471047
.consecutiveDeclarationsOnSameLine,
10481048
fixIts: [
1049-
FixIt(message: .insertSemicolon, changes: .makePresent(semicolon))
1050-
],
1049+
node.lastToken(viewMode: .sourceAccurate).map {
1050+
FixIt(
1051+
message: .insertNewline,
1052+
changes: [
1053+
.replaceTrailingTrivia(token: $0, newTrivia: .newlines(1))
1054+
]
1055+
)
1056+
},
1057+
FixIt(message: .insertSemicolon, changes: .makePresent(semicolon)),
1058+
].compactMap { $0 },
10511059
handledNodes: [semicolon.id]
10521060
)
10531061
} else {

Tests/SwiftParserTest/translated/ConsecutiveStatementsTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ final class ConsecutiveStatementsTests: XCTestCase {
102102
}
103103
""",
104104
diagnostics: [
105-
DiagnosticSpec(locationMarker: "1️⃣", message: "consecutive declarations on a line must be separated by ';'", fixIts: ["insert ';'"]),
106-
DiagnosticSpec(locationMarker: "2️⃣", message: "consecutive declarations on a line must be separated by ';'", fixIts: ["insert ';'"]),
105+
DiagnosticSpec(locationMarker: "1️⃣", message: "consecutive declarations on a line must be separated by ';'", fixIts: ["insert newline", "insert ';'"]),
106+
DiagnosticSpec(locationMarker: "2️⃣", message: "consecutive declarations on a line must be separated by ';'", fixIts: ["insert newline", "insert ';'"]),
107107
DiagnosticSpec(locationMarker: "3️⃣", message: "consecutive statements on a line must be separated by ';'", fixIts: ["insert ';'"]),
108108
DiagnosticSpec(locationMarker: "4️⃣", message: "consecutive statements on a line must be separated by ';'", fixIts: ["insert ';'"]),
109109
DiagnosticSpec(locationMarker: "5️⃣", message: "consecutive statements on a line must be separated by ';'", fixIts: ["insert ';'"]),

0 commit comments

Comments
 (0)