zig fmt: handle empty block with comment inside

This commit is contained in:
Andrew Kelley 2018-05-26 18:29:14 -04:00
parent 7e900d28be
commit b8d4e05361
2 changed files with 12 additions and 1 deletions

View File

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

View File

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