Skip to content

Commit f6c8ffc

Browse files
authored
Merge pull request swiftlang#9 from allevato/sr-11116
Ensure line breaks between type members wrapped in an `#if` block.
2 parents df19306 + 9d31b89 commit f6c8ffc

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,11 @@ private final class TokenStreamCreator: SyntaxVisitor {
819819
}
820820

821821
func visit(_ node: MemberDeclBlockSyntax) -> SyntaxVisitorContinueKind {
822-
insertTokens(.break(.reset, size: 0), .newline, betweenElementsOf: node.members)
822+
return .visitChildren
823+
}
824+
825+
func visit(_ node: MemberDeclListSyntax) -> SyntaxVisitorContinueKind {
826+
insertTokens(.break(.reset, size: 0), .newline, betweenElementsOf: node)
823827
return .visitChildren
824828
}
825829

Tests/SwiftFormatPrettyPrintTests/IfConfigTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,29 @@ public class IfConfigTests: PrettyPrintTestCase {
5555

5656
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
5757
}
58+
59+
public func testPoundIfAroundMembers() {
60+
let input =
61+
"""
62+
class Foo {
63+
#if DEBUG
64+
var bar: String
65+
var baz: String
66+
#endif
67+
}
68+
"""
69+
70+
let expected =
71+
"""
72+
class Foo {
73+
#if DEBUG
74+
var bar: String
75+
var baz: String
76+
#endif
77+
}
78+
79+
"""
80+
81+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
82+
}
5883
}

Tests/SwiftFormatPrettyPrintTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ extension IfConfigTests {
248248
// to regenerate.
249249
static let __allTests__IfConfigTests = [
250250
("testBasicIfConfig", testBasicIfConfig),
251+
("testPoundIfAroundMembers", testPoundIfAroundMembers),
251252
]
252253
}
253254

0 commit comments

Comments
 (0)