zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 8e6ff8d615820f7f732724a5db1639ae5f12fb4e (tree)
parent 5866dfe4d970ad105e8e580b6feaab8c7c5e82dc
Author: Shritesh Bhattarai <shritesh@shritesh.com>
Date:   Thu,  4 Apr 2019 18:33:32 -0500

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

* fmt: format multi line only on trailing comma


Diffstat:
Mstd/zig/parser_test.zig | 19+++++++++++++++++++
Mstd/zig/render.zig | 6+-----
2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig @@ -584,6 +584,25 @@ test "zig fmt: trailing comma on fn call" { ); } +test "zig fmt: multi line arguments without last comma" { + try testTransform( + \\pub fn foo( + \\ a: usize, + \\ b: usize, + \\ c: usize, + \\ d: usize + \\) usize { + \\ return a + b + c + d; + \\} + \\ + , + \\pub fn foo(a: usize, b: usize, c: usize, d: usize) usize { + \\ return a + b + c + d; + \\} + \\ + ); +} + test "zig fmt: empty block with only comment" { try testCanonical( \\comptime { diff --git a/std/zig/render.zig b/std/zig/render.zig @@ -1158,12 +1158,8 @@ fn renderExpression( const maybe_comma = tree.prevToken(rparen); break :blk tree.tokens.at(maybe_comma).id == Token.Id.Comma; }; - const src_params_same_line = blk: { - const loc = tree.tokenLocation(tree.tokens.at(lparen).end, rparen); - break :blk loc.line == 0; - }; - if (!src_params_trailing_comma and src_params_same_line) { + if (!src_params_trailing_comma) { try renderToken(tree, stream, lparen, indent, start_col, Space.None); // ( // render all on one line, no trailing comma