Commit db4c15be50

Andrew Kelley <andrew@ziglang.org>
2021-02-24 07:01:16
zig fmt: respect extra newline between fn and pub usingnamespace
1 parent bf64220
Changed files (2)
lib/std/zig/ast.zig
@@ -321,7 +321,6 @@ pub const Tree = struct {
         while (true) switch (tags[n]) {
             .root => return 0,
 
-            .@"usingnamespace",
             .test_decl,
             .@"errdefer",
             .@"defer",
@@ -468,6 +467,14 @@ pub const Tree = struct {
                 return i - end_offset;
             },
 
+            .@"usingnamespace" => {
+                const main_token = main_tokens[n];
+                if (main_token > 0 and token_tags[main_token - 1] == .keyword_pub) {
+                    end_offset += 1;
+                }
+                return main_token - end_offset;
+            },
+
             .async_call_one,
             .async_call_one_comma,
             .async_call,
lib/std/zig/parser_test.zig
@@ -4178,17 +4178,16 @@ test "zig fmt: for loop with ptr payload and index" {
 //    );
 //}
 
-// TODO
-//test "zig fmt: respect extra newline between fn and pub usingnamespace" {
-//    try testCanonical(
-//        \\fn foo() void {
-//        \\    bar();
-//        \\}
-//        \\
-//        \\pub usingnamespace baz;
-//        \\
-//    );
-//}
+test "zig fmt: respect extra newline between fn and pub usingnamespace" {
+    try testCanonical(
+        \\fn foo() void {
+        \\    bar();
+        \\}
+        \\
+        \\pub usingnamespace baz;
+        \\
+    );
+}
 
 // TODO
 //test "zig fmt: respect extra newline between switch items" {