| author | |
| committer | |
| log | 8e6ff8d615820f7f732724a5db1639ae5f12fb4e |
| tree | 348d3de4804f8602ac159e87bb24389c9431a356 |
| parent | 5866dfe4d970ad105e8e580b6feaab8c7c5e82dc |
* fmt: format multi line only on trailing comma
2 files changed, 20 insertions(+), 5 deletions(-)
std/zig/parser_test.zig+19| ... | @@ -584,6 +584,25 @@ test "zig fmt: trailing comma on fn call" { | ... | @@ -584,6 +584,25 @@ test "zig fmt: trailing comma on fn call" { |
| 584 | ); | 584 | ); |
| 585 | } | 585 | } |
| 586 | 586 | ||
| 587 | test "zig fmt: multi line arguments without last comma" { | ||
| 588 | try testTransform( | ||
| 589 | \\pub fn foo( | ||
| 590 | \\ a: usize, | ||
| 591 | \\ b: usize, | ||
| 592 | \\ c: usize, | ||
| 593 | \\ d: usize | ||
| 594 | \\) usize { | ||
| 595 | \\ return a + b + c + d; | ||
| 596 | \\} | ||
| 597 | \\ | ||
| 598 | , | ||
| 599 | \\pub fn foo(a: usize, b: usize, c: usize, d: usize) usize { | ||
| 600 | \\ return a + b + c + d; | ||
| 601 | \\} | ||
| 602 | \\ | ||
| 603 | ); | ||
| 604 | } | ||
| 605 | |||
| 587 | test "zig fmt: empty block with only comment" { | 606 | test "zig fmt: empty block with only comment" { |
| 588 | try testCanonical( | 607 | try testCanonical( |
| 589 | \\comptime { | 608 | \\comptime { |
std/zig/render.zig+1-5| ... | @@ -1158,12 +1158,8 @@ fn renderExpression( | ... | @@ -1158,12 +1158,8 @@ fn renderExpression( |
| 1158 | const maybe_comma = tree.prevToken(rparen); | 1158 | const maybe_comma = tree.prevToken(rparen); |
| 1159 | break :blk tree.tokens.at(maybe_comma).id == Token.Id.Comma; | 1159 | break :blk tree.tokens.at(maybe_comma).id == Token.Id.Comma; |
| 1160 | }; | 1160 | }; |
| 1161 | const src_params_same_line = blk: { | ||
| 1162 | const loc = tree.tokenLocation(tree.tokens.at(lparen).end, rparen); | ||
| 1163 | break :blk loc.line == 0; | ||
| 1164 | }; | ||
| 1165 | 1161 | ||
| 1166 | if (!src_params_trailing_comma and src_params_same_line) { | 1162 | if (!src_params_trailing_comma) { |
| 1167 | try renderToken(tree, stream, lparen, indent, start_col, Space.None); // ( | 1163 | try renderToken(tree, stream, lparen, indent, start_col, Space.None); // ( |
| 1168 | 1164 | ||
| 1169 | // render all on one line, no trailing comma | 1165 | // render all on one line, no trailing comma |