zig fmt: delete empty comments that do nothing

This commit is contained in:
Andrew Kelley 2018-05-26 23:17:24 -04:00
parent b184ae5ca5
commit afdfbc0367
2 changed files with 23 additions and 2 deletions

View File

@ -28,6 +28,12 @@ test "zig fmt: array literal with hint" {
\\ 5,
\\ 6,
\\ 7 };
\\const a = []u8{
\\ 1, 2,
\\ 3, 4, //
\\ 5, 6, //
\\ 7, 8, //
\\};
,
\\const a = []u8{
\\ 1, 2, //
@ -53,6 +59,16 @@ test "zig fmt: array literal with hint" {
\\ 5, 6, //
\\ 7,
\\};
\\const a = []u8{
\\ 1,
\\ 2,
\\ 3,
\\ 4,
\\ 5,
\\ 6,
\\ 7,
\\ 8,
\\};
\\
);
}

View File

@ -1583,8 +1583,13 @@ fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent
}
}
if (space == Space.IgnoreEmptyComment and mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ").len == 2) {
return stream.writeByte(' ');
const comment_is_empty = mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ").len == 2;
if (comment_is_empty) {
switch (space) {
Space.IgnoreEmptyComment => return stream.writeByte(' '),
Space.Newline => return stream.writeByte('\n'),
else => {},
}
}
var loc = tree.tokenLocationPtr(token.end, next_token);