Skip to content

Commit 0510caf

Browse files
committed
Fix incorrect spacing when pretty-printing @_documentation
With attribute such as `@_documentation(visibility: private)`, swift-format incorrectly prints no spacing between `visibility` and `private`.
1 parent 5eb3d20 commit 0510caf

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,11 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
17991799
return .visitChildren
18001800
}
18011801

1802+
override func visit(_ node: DocumentationAttributeArgumentSyntax) -> SyntaxVisitorContinueKind {
1803+
after(node.colon, tokens: .break(.same, size: 1))
1804+
return .visitChildren
1805+
}
1806+
18021807
override func visit(_ node: AvailabilityLabeledArgumentSyntax) -> SyntaxVisitorContinueKind {
18031808
before(node.label, tokens: .open)
18041809

Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ final class AttributeTests: PrettyPrintTestCase {
2626
assertPrettyPrintEqual(input: input, expected: expected, linelength: 60)
2727
}
2828

29+
func testAttributeParamSpacingInDocVisibility() {
30+
let input =
31+
"""
32+
@_documentation( visibility :private )
33+
func f() {}
34+
"""
35+
36+
let expected =
37+
"""
38+
@_documentation(visibility: private)
39+
func f() {}
40+
41+
"""
42+
43+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 60)
44+
}
45+
2946
func testAttributeBinPackedWrapping() {
3047
let input =
3148
"""

0 commit comments

Comments
 (0)