Commit b8d4e05361

Andrew Kelley <superjoe30@gmail.com>
2018-05-27 00:29:14
zig fmt: handle empty block with comment inside
1 parent 7e900d2
Changed files (2)
std/zig/parser_test.zig
@@ -1,3 +1,14 @@
+test "zig fmt: empty block with only comment" {
+    try testCanonical(
+        \\comptime {
+        \\    {
+        \\        // comment
+        \\    }
+        \\}
+        \\
+    );
+}
+
 test "zig fmt: no trailing comma on struct decl" {
     try testTransform(
         \\const RoundParam = struct {
std/zig/render.zig
@@ -1519,7 +1519,7 @@ fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent
 
                     const after_comment_token = tree.tokens.at(token_index + offset);
                     const next_line_indent = switch (after_comment_token.id) {
-                        Token.Id.RParen, Token.Id.RBrace, Token.Id.RBracket => indent,
+                        Token.Id.RParen, Token.Id.RBrace, Token.Id.RBracket => indent - indent_delta,
                         else => indent,
                     };
                     try stream.writeByteNTimes(' ', next_line_indent);