Skip to content

Commit afdfbc0

Browse files
committed
zig fmt: delete empty comments that do nothing
1 parent b184ae5 commit afdfbc0

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

std/zig/parser_test.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

0 commit comments

Comments
 (0)