File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
Sources/SwiftFormatPrettyPrint
Tests/SwiftFormatPrettyPrintTests Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -962,7 +962,13 @@ private final class TokenStreamCreator: SyntaxVisitor {
962
962
}
963
963
964
964
override func visit( _ node: ConditionElementSyntax ) -> SyntaxVisitorContinueKind {
965
- after ( node. trailingComma, tokens: . break)
965
+ before ( node. firstToken, tokens: . open)
966
+ if let comma = node. trailingComma {
967
+ after ( comma, tokens: . close, . break)
968
+ }
969
+ else {
970
+ after ( node. lastToken, tokens: . close)
971
+ }
966
972
return . visitChildren
967
973
}
968
974
@@ -1375,9 +1381,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
1375
1381
}
1376
1382
1377
1383
override func visit( _ node: OptionalBindingConditionSyntax ) -> SyntaxVisitorContinueKind {
1378
- before ( node. firstToken, tokens: . open)
1379
1384
after ( node. letOrVarKeyword, tokens: . break)
1380
- after ( node. lastToken, tokens: . close)
1381
1385
return . visitChildren
1382
1386
}
1383
1387
Original file line number Diff line number Diff line change @@ -182,4 +182,26 @@ public class IfStmtTests: PrettyPrintTestCase {
182
182
183
183
assertPrettyPrintEqual ( input: input, expected: expected, linelength: 30 )
184
184
}
185
+
186
+ public func testIfLetStatements( ) {
187
+ let input =
188
+ """
189
+ if let SomeReallyLongVar = Some.More.Stuff(), let a = myfunc() {
190
+ // do stuff
191
+ }
192
+ """
193
+
194
+ let expected =
195
+ """
196
+ if let SomeReallyLongVar
197
+ = Some.More.Stuff(), let a = myfunc()
198
+ {
199
+ // do stuff
200
+ }
201
+
202
+ """
203
+
204
+ // The line length ends on the last paren of .Stuff()
205
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 44 )
206
+ }
185
207
}
You can’t perform that action at this time.
0 commit comments