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

* fmt: format multi line only on trailing comma
master
Shritesh Bhattarai 2019-04-04 18:33:32 -05:00 committed by Andrew Kelley
parent 5866dfe4d9
commit 8e6ff8d615
2 changed files with 20 additions and 5 deletions

View File

@ -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 {

View File

@ -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