authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-26 23:17:24-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-26 23:25:04-04:00
logafdfbc0367b261ea43d5618027e23022c01e2c93
tree69ad57dfa99ccd0043a12c743fc75255bbd22b28
parentb184ae5ca5d3d3c0a4b9de564a6e30555e596e65

zig fmt: delete empty comments that do nothing


2 files changed, 23 insertions(+), 2 deletions(-)

std/zig/parser_test.zig+16
......@@ -28,6 +28,12 @@ test "zig fmt: array literal with hint" {
2828 \\ 5,
2929 \\ 6,
3030 \\ 7 };
31 \\const a = []u8{
32 \\ 1, 2,
33 \\ 3, 4, //
34 \\ 5, 6, //
35 \\ 7, 8, //
36 \\};
3137 ,
3238 \\const a = []u8{
3339 \\ 1, 2, //
......@@ -53,6 +59,16 @@ test "zig fmt: array literal with hint" {
5359 \\ 5, 6, //
5460 \\ 7,
5561 \\};
62 \\const a = []u8{
63 \\ 1,
64 \\ 2,
65 \\ 3,
66 \\ 4,
67 \\ 5,
68 \\ 6,
69 \\ 7,
70 \\ 8,
71 \\};
5672 \\
5773 );
5874}
std/zig/render.zig+7-2
......@@ -1583,8 +1583,13 @@ fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent
15831583 }
15841584 }
15851585
1586 if (space == Space.IgnoreEmptyComment and mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ").len == 2) {
1587 return stream.writeByte(' ');
1586 const comment_is_empty = mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ").len == 2;
1587 if (comment_is_empty) {
1588 switch (space) {
1589 Space.IgnoreEmptyComment => return stream.writeByte(' '),
1590 Space.Newline => return stream.writeByte('\n'),
1591 else => {},
1592 }
15881593 }
15891594
15901595 var loc = tree.tokenLocationPtr(token.end, next_token);