File tree 2 files changed +51
-6
lines changed
Sources/SwiftFormatPrettyPrint
Tests/SwiftFormatPrettyPrintTests 2 files changed +51
-6
lines changed Original file line number Diff line number Diff line change @@ -427,10 +427,8 @@ private final class TokenStreamCreator: SyntaxVisitor {
427
427
}
428
428
429
429
override func visit( _ node: CodeBlockItemListSyntax ) {
430
- if node. parent is AccessorBlockSyntax , node. count > 0 {
431
- for i in 0 ..< ( node. count - 1 ) {
432
- after ( node [ i] . lastToken, tokens: . newline)
433
- }
430
+ if node. parent is AccessorBlockSyntax || node. parent is ClosureExprSyntax , node. count > 0 {
431
+ insertToken ( . newline, betweenChildrenOf: node)
434
432
}
435
433
super. visit ( node)
436
434
}
Original file line number Diff line number Diff line change @@ -47,7 +47,8 @@ public class FunctionCallTests: PrettyPrintTestCase {
47
47
public func testBasicFunctionClosures( ) {
48
48
let input =
49
49
"""
50
- funcCall(closure: { < })
50
+ funcCall(closure: <)
51
+ funcCall(closure: { 4 })
51
52
funcCall(closure: { $0 < $1 })
52
53
funcCall(closure: { s1, s2 in s1 < s2 })
53
54
funcCall(closure: { s1, s2 in return s1 < s2})
@@ -59,7 +60,8 @@ public class FunctionCallTests: PrettyPrintTestCase {
59
60
60
61
let expected =
61
62
"""
62
- funcCall(closure: { < })
63
+ funcCall(closure: <)
64
+ funcCall(closure: { 4 })
63
65
funcCall(closure: { $0 < $1 })
64
66
funcCall(closure: { s1, s2 in
65
67
s1 < s2
@@ -117,4 +119,49 @@ public class FunctionCallTests: PrettyPrintTestCase {
117
119
118
120
assertPrettyPrintEqual ( input: input, expected: expected, linelength: 40 )
119
121
}
122
+
123
+ public func testClosuresWithIfs( ) {
124
+ let input =
125
+ """
126
+ let a = afunc() {
127
+ if condition1 {
128
+ return true
129
+ }
130
+ return false
131
+ }
132
+
133
+ let a = afunc() {
134
+ if condition1 {
135
+ return true
136
+ }
137
+ if condition2 {
138
+ return true
139
+ }
140
+ return false
141
+ }
142
+ """
143
+
144
+ let expected =
145
+ """
146
+ let a = afunc() {
147
+ if condition1 {
148
+ return true
149
+ }
150
+ return false
151
+ }
152
+
153
+ let a = afunc() {
154
+ if condition1 {
155
+ return true
156
+ }
157
+ if condition2 {
158
+ return true
159
+ }
160
+ return false
161
+ }
162
+
163
+ """
164
+
165
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 40 )
166
+ }
120
167
}
You can’t perform that action at this time.
0 commit comments