Skip to content

Commit 324166c

Browse files
authored
Merge pull request #1351 from kimdv/kimdv/fix-leading-newline-in-source-file-syntax
2 parents 8eb538d + 8182b90 commit 324166c

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

CodeGeneration/Sources/generate-swiftsyntax/templates/basicformat/BasicFormatFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let basicFormatFile = SourceFileSyntax(leadingTrivia: generateCopyrightHeader(fo
6666
indentationLevel += 1
6767
}
6868
if let parent = node.parent, childrenSeparatedByNewline(parent) {
69-
putNextTokenOnNewLine = true
69+
putNextTokenOnNewLine = true && node.previousToken != nil
7070
}
7171
}
7272
"""

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ open class BasicFormat: SyntaxRewriter {
3535
indentationLevel += 1
3636
}
3737
if let parent = node.parent, childrenSeparatedByNewline(parent) {
38-
putNextTokenOnNewLine = true
38+
putNextTokenOnNewLine = true && node.previousToken != nil
3939
}
4040
}
4141

Tests/SwiftSyntaxBuilderTest/SourceFileTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ final class SourceFileTests: XCTestCase {
3131
AssertBuildResult(
3232
source,
3333
"""
34-
3534
import Foundation
3635
import UIKit
3736
class SomeViewController {
3837
let tableView: UITableView
3938
}
40-
"""
39+
""",
40+
trimTrailingWhitespace: false
4141
)
4242
}
4343
}

Tests/SwiftSyntaxBuilderTest/StringInterpolationTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ final class StringInterpolationTests: XCTestCase {
278278
"""
279279
func plusOne(base: Int) -> Int {
280280
switch base {
281-
282281
case 0:
283282
return 1
284283
case 1:
@@ -323,7 +322,6 @@ final class StringInterpolationTests: XCTestCase {
323322
"""
324323
func plusOne(base: Int) -> Int {
325324
switch base {
326-
327325
case 0:
328326
return 1
329327
case 1:

0 commit comments

Comments
 (0)