Skip to content

Commit 36ba8dc

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 26d83e5 commit 36ba8dc

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
@@ -1802,6 +1802,11 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
18021802
override func visit(_ node: OriginallyDefinedInAttributeArgumentsSyntax) -> SyntaxVisitorContinueKind {
18031803
after(node.colon.lastToken(viewMode: .sourceAccurate), tokens: .break(.same, size: 1))
18041804
after(node.comma.lastToken(viewMode: .sourceAccurate), tokens: .break(.same, size: 1))
1805+
return .visitChildren
1806+
}
1807+
1808+
override func visit(_ node: DocumentationAttributeArgumentSyntax) -> SyntaxVisitorContinueKind {
1809+
after(node.colon, tokens: .break(.same, size: 1))
18051810
return .visitChildren
18061811
}
18071812

Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift

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

46+
func testAttributeParamSpacingInDocVisibility() {
47+
let input =
48+
"""
49+
@_documentation( visibility :private )
50+
func f() {}
51+
"""
52+
53+
let expected =
54+
"""
55+
@_documentation(visibility: private)
56+
func f() {}
57+
58+
"""
59+
60+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 60)
61+
}
62+
4663
func testAttributeBinPackedWrapping() {
4764
let input =
4865
"""

0 commit comments

Comments
 (0)