Commit afdfbc0367

Andrew Kelley <superjoe30@gmail.com>
2018-05-27 05:17:24
zig fmt: delete empty comments that do nothing
1 parent b184ae5
Changed files (2)
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,
+        \\};
         \\
     );
 }
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);