Commit 8e6ff8d615

Shritesh Bhattarai <shritesh@shritesh.com>
2019-04-05 01:33:32
fmt: format multi line only on trailing comma (#2184)
* fmt: format multi line only on trailing comma
1 parent 5866dfe
Changed files (2)
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 {
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