authorgravatar for shritesh@shritesh.comShritesh Bhattarai <shritesh@shritesh.com> 2019-04-04 18:33:32-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-04 19:33:32-04:00
log8e6ff8d615820f7f732724a5db1639ae5f12fb4e
tree348d3de4804f8602ac159e87bb24389c9431a356
parent5866dfe4d970ad105e8e580b6feaab8c7c5e82dc

fmt: format multi line only on trailing comma (#2184)

* 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" {
584584 );
585585}
586586
587test "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
587606test "zig fmt: empty block with only comment" {
588607 try testCanonical(
589608 \\comptime {
std/zig/render.zig+1-5
......@@ -1158,12 +1158,8 @@ fn renderExpression(
11581158 const maybe_comma = tree.prevToken(rparen);
11591159 break :blk tree.tokens.at(maybe_comma).id == Token.Id.Comma;
11601160 };
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 };
11651161
1166 if (!src_params_trailing_comma and src_params_same_line) {
1162 if (!src_params_trailing_comma) {
11671163 try renderToken(tree, stream, lparen, indent, start_col, Space.None); // (
11681164
11691165 // render all on one line, no trailing comma