Skip to content

Commit

Permalink
Merge pull request #719 from apple/dd/documentation-vilibility-printing
Browse files Browse the repository at this point in the history
Fix incorrect spacing when pretty-printing @_documentation
  • Loading branch information
allevato authored Apr 18, 2024
2 parents 26d83e5 + 36ba8dc commit fdb4f43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,11 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
override func visit(_ node: OriginallyDefinedInAttributeArgumentsSyntax) -> SyntaxVisitorContinueKind {
after(node.colon.lastToken(viewMode: .sourceAccurate), tokens: .break(.same, size: 1))
after(node.comma.lastToken(viewMode: .sourceAccurate), tokens: .break(.same, size: 1))
return .visitChildren
}

override func visit(_ node: DocumentationAttributeArgumentSyntax) -> SyntaxVisitorContinueKind {
after(node.colon, tokens: .break(.same, size: 1))
return .visitChildren
}

Expand Down
17 changes: 17 additions & 0 deletions Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ final class AttributeTests: PrettyPrintTestCase {
assertPrettyPrintEqual(input: input, expected: expected, linelength: 60)
}

func testAttributeParamSpacingInDocVisibility() {
let input =
"""
@_documentation( visibility :private )
func f() {}
"""

let expected =
"""
@_documentation(visibility: private)
func f() {}
"""

assertPrettyPrintEqual(input: input, expected: expected, linelength: 60)
}

func testAttributeBinPackedWrapping() {
let input =
"""
Expand Down

0 comments on commit fdb4f43

Please sign in to comment.