authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-02-22 23:14:01+01:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-02-22 23:51:54+01:00
log550688f427a2303f5e309a269def4d8be532cc54
tree2c054ae7c1f0dfa94f6d5d2c556ccb65f01dfef6
parent4758e0c9a662b59e071b52fbcc931fae138292d7
signaturelock-open Commit is signed but in an unrecognized format.

zig fmt: insert trailing comma in switches


2 files changed, 33 insertions(+), 29 deletions(-)

lib/std/zig/parser_test.zig+28-28
...@@ -2103,34 +2103,34 @@ test "zig fmt: same line comments in expression" {...@@ -2103,34 +2103,34 @@ test "zig fmt: same line comments in expression" {
2103 );2103 );
2104}2104}
21052105
2106//test "zig fmt: add comma on last switch prong" {2106test "zig fmt: add comma on last switch prong" {
2107// try testTransform(2107 try testTransform(
2108// \\test "aoeu" {2108 \\test "aoeu" {
2109// \\switch (self.init_arg_expr) {2109 \\switch (self.init_arg_expr) {
2110// \\ InitArg.Type => |t| { },2110 \\ InitArg.Type => |t| { },
2111// \\ InitArg.None,2111 \\ InitArg.None,
2112// \\ InitArg.Enum => { }2112 \\ InitArg.Enum => { }
2113// \\}2113 \\}
2114// \\ switch (self.init_arg_expr) {2114 \\ switch (self.init_arg_expr) {
2115// \\ InitArg.Type => |t| { },2115 \\ InitArg.Type => |t| { },
2116// \\ InitArg.None,2116 \\ InitArg.None,
2117// \\ InitArg.Enum => { }//line comment2117 \\ InitArg.Enum => { }//line comment
2118// \\ }2118 \\ }
2119// \\}2119 \\}
2120// ,2120 ,
2121// \\test "aoeu" {2121 \\test "aoeu" {
2122// \\ switch (self.init_arg_expr) {2122 \\ switch (self.init_arg_expr) {
2123// \\ InitArg.Type => |t| {},2123 \\ InitArg.Type => |t| {},
2124// \\ InitArg.None, InitArg.Enum => {},2124 \\ InitArg.None, InitArg.Enum => {},
2125// \\ }2125 \\ }
2126// \\ switch (self.init_arg_expr) {2126 \\ switch (self.init_arg_expr) {
2127// \\ InitArg.Type => |t| {},2127 \\ InitArg.Type => |t| {},
2128// \\ InitArg.None, InitArg.Enum => {}, //line comment2128 \\ InitArg.None, InitArg.Enum => {}, //line comment
2129// \\ }2129 \\ }
2130// \\}2130 \\}
2131// \\2131 \\
2132// );2132 );
2133//}2133}
21342134
2135test "zig fmt: same-line comment after a statement" {2135test "zig fmt: same-line comment after a statement" {
2136 try testCanonical(2136 try testCanonical(
lib/std/zig/render.zig+5-1
...@@ -1948,7 +1948,7 @@ const Space = enum {...@@ -1948,7 +1948,7 @@ const Space = enum {
1948 space,1948 space,
1949 /// Output the token lexeme followed by a newline.1949 /// Output the token lexeme followed by a newline.
1950 newline,1950 newline,
1951 /// Additionally consume the next token if it is a comma.1951 /// If the next token is a comma, render it as well. If not, insert one.
1952 /// In either case, a newline will be inserted afterwards.1952 /// In either case, a newline will be inserted afterwards.
1953 comma,1953 comma,
1954 /// Additionally consume the next token if it is a comma.1954 /// Additionally consume the next token if it is a comma.
...@@ -1968,6 +1968,10 @@ fn renderToken(ais: *Ais, tree: ast.Tree, token_index: ast.TokenIndex, space: Sp...@@ -1968,6 +1968,10 @@ fn renderToken(ais: *Ais, tree: ast.Tree, token_index: ast.TokenIndex, space: Sp
19681968
1969 try ais.writer().writeAll(lexeme);1969 try ais.writer().writeAll(lexeme);
19701970
1971 if (space == .comma and token_tags[token_index + 1] != .comma) {
1972 try ais.writer().writeByte(',');
1973 }
1974
1971 const comment = try renderComments(ais, tree, token_start + lexeme.len, token_starts[token_index + 1]);1975 const comment = try renderComments(ais, tree, token_start + lexeme.len, token_starts[token_index + 1]);
1972 switch (space) {1976 switch (space) {
1973 .none => {},1977 .none => {},