zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit afdfbc0367b261ea43d5618027e23022c01e2c93 (tree)
parent b184ae5ca5d3d3c0a4b9de564a6e30555e596e65
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Sat, 26 May 2018 23:17:24 -0400

zig fmt: delete empty comments that do nothing

Diffstat:
Mstd/zig/parser_test.zig | 16++++++++++++++++
Mstd/zig/render.zig | 9+++++++--
2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig @@ -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, + \\}; \\ ); } diff --git a/std/zig/render.zig b/std/zig/render.zig @@ -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);