Skip to content

Commit 818c7c6

Browse files
authored
Merge pull request #119 from dylansturg/break_close_order
Reverse `.break(.close)` and `.close` for array and dict literals.
2 parents 725aacf + 42e19c7 commit 818c7c6

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
692692

693693
func visit(_ node: ArrayExprSyntax) -> SyntaxVisitorContinueKind {
694694
after(node.leftSquare, tokens: .break(.open, size: 0), .open)
695-
before(node.rightSquare, tokens: .close, .break(.close, size: 0))
695+
before(node.rightSquare, tokens: .break(.close, size: 0), .close)
696696
return .visitChildren
697697
}
698698

@@ -709,7 +709,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
709709

710710
func visit(_ node: DictionaryExprSyntax) -> SyntaxVisitorContinueKind {
711711
after(node.leftSquare, tokens: .break(.open, size: 0), .open)
712-
before(node.rightSquare, tokens: .close, .break(.close, size: 0))
712+
before(node.rightSquare, tokens: .break(.close, size: 0), .close)
713713
return .visitChildren
714714
}
715715

Tests/SwiftFormatPrettyPrintTests/ArrayDeclTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class ArrayDeclTests: PrettyPrintTestCase {
44
"""
55
let a = [1, 2, 3]
66
let a: [Bool] = [false, true, true, false]
7+
let a = [11111111, 2222222, 33333333, 4444444]
78
let a: [String] = ["One", "Two", "Three", "Four"]
89
let a: [String] = ["One", "Two", "Three", "Four", "Five", "Six", "Seven"]
910
let a: [String] = ["One", "Two", "Three", "Four", "Five", "Six", "Seven",]
@@ -13,6 +14,9 @@ public class ArrayDeclTests: PrettyPrintTestCase {
1314
"""
1415
let a = [1, 2, 3]
1516
let a: [Bool] = [false, true, true, false]
17+
let a = [
18+
11111111, 2222222, 33333333, 4444444
19+
]
1620
let a: [String] = [
1721
"One", "Two", "Three", "Four"
1822
]

Tests/SwiftFormatPrettyPrintTests/DictionaryDeclTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class DictionaryDeclTests: PrettyPrintTestCase {
44
"""
55
let a = [1: "a", 2: "b", 3: "c"]
66
let a: [Int: String] = [1: "a", 2: "b", 3: "c"]
7+
let a = [10000: "abc", 20000: "def", 30000: "ghij"]
78
let a: [Int: String] = [1: "a", 2: "b", 3: "c", 4: "d"]
89
let a: [Int: String] = [1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g"]
910
let a: [Int: String] = [1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g",]
@@ -13,6 +14,9 @@ public class DictionaryDeclTests: PrettyPrintTestCase {
1314
"""
1415
let a = [1: "a", 2: "b", 3: "c"]
1516
let a: [Int: String] = [1: "a", 2: "b", 3: "c"]
17+
let a = [
18+
10000: "abc", 20000: "def", 30000: "ghij"
19+
]
1620
let a: [Int: String] = [
1721
1: "a", 2: "b", 3: "c", 4: "d"
1822
]

0 commit comments

Comments
 (0)