Skip to content

Commit e5e2fad

Browse files
authored
Merge pull request #550 from allevato/backdeploy
Fix formatting of `@backDeploy` attribute.
2 parents 94de8e5 + b9cd907 commit e5e2fad

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,13 +1783,29 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
17831783
return .visitChildren
17841784
}
17851785

1786+
override func visit(_ node: AvailabilityVersionRestrictionListSyntax)
1787+
-> SyntaxVisitorContinueKind
1788+
{
1789+
insertTokens(.break(.same, size: 1), betweenElementsOf: node)
1790+
return .visitChildren
1791+
}
1792+
17861793
override func visit(_ node: AvailabilityVersionRestrictionSyntax) -> SyntaxVisitorContinueKind {
17871794
before(node.firstToken(viewMode: .sourceAccurate), tokens: .open)
17881795
after(node.platform, tokens: .break(.continue, size: 1))
17891796
after(node.lastToken(viewMode: .sourceAccurate), tokens: .close)
17901797
return .visitChildren
17911798
}
17921799

1800+
override func visit(_ node: BackDeployedAttributeSpecListSyntax) -> SyntaxVisitorContinueKind {
1801+
before(
1802+
node.platforms.firstToken(viewMode: .sourceAccurate),
1803+
tokens: .break(.open, size: 1), .open(argumentListConsistency()))
1804+
after(
1805+
node.platforms.lastToken(viewMode: .sourceAccurate), tokens: .break(.close, size: 0), .close)
1806+
return .visitChildren
1807+
}
1808+
17931809
override func visit(_ node: ConditionElementSyntax) -> SyntaxVisitorContinueKind {
17941810
before(node.firstToken(viewMode: .sourceAccurate), tokens: .open)
17951811
if let comma = node.trailingComma {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
final class BackDeployAttributeTests: PrettyPrintTestCase {
2+
func testSpacingAndWrapping() {
3+
let input =
4+
"""
5+
@backDeployed(before:iOS 17)
6+
public func hello() {}
7+
8+
@backDeployed(before:iOS 17,macOS 14)
9+
public func hello() {}
10+
11+
@backDeployed(before:iOS 17,macOS 14,tvOS 17)
12+
public func hello() {}
13+
"""
14+
15+
let expected80 =
16+
"""
17+
@backDeployed(before: iOS 17)
18+
public func hello() {}
19+
20+
@backDeployed(before: iOS 17, macOS 14)
21+
public func hello() {}
22+
23+
@backDeployed(before: iOS 17, macOS 14, tvOS 17)
24+
public func hello() {}
25+
26+
"""
27+
28+
assertPrettyPrintEqual(input: input, expected: expected80, linelength: 80)
29+
30+
let expected28 =
31+
"""
32+
@backDeployed(
33+
before: iOS 17
34+
)
35+
public func hello() {}
36+
37+
@backDeployed(
38+
before: iOS 17, macOS 14
39+
)
40+
public func hello() {}
41+
42+
@backDeployed(
43+
before:
44+
iOS 17, macOS 14,
45+
tvOS 17
46+
)
47+
public func hello() {}
48+
49+
"""
50+
51+
assertPrettyPrintEqual(input: input, expected: expected28, linelength: 28)
52+
}
53+
}

0 commit comments

Comments
 (0)