authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-12-10 23:26:38+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-11 02:34:44-05:00
logfa6449dac06435175bee6113a0676ef2d43d777c
tree5daa08b68b8294a108cfa1edb8e997524cade8f1
parent64a590a31194a778b494937e2f91642b80e3f4d0

zig fmt: Fix alignment of initializer elements

Resetting `column_counter` is not needed as the effective column number is calculated by taking that value modulo `row_size`. Closes #7289

2 files changed, 25 insertions(+), 7 deletions(-)

lib/std/zig/parser_test.zig+19-1
......@@ -286,7 +286,7 @@ test "zig fmt: respect line breaks after var declarations" {
286286 \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
287287 \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];
288288 \\
289 );
289 );
290290}
291291
292292test "zig fmt: multiline string mixed with comments" {
......@@ -563,6 +563,24 @@ test "zig fmt: anon literal in array" {
563563 );
564564}
565565
566test "zig fmt: alignment in anonymous literal" {
567 try testTransform(
568 \\const a = .{
569 \\ "U", "L", "F",
570 \\ "U'",
571 \\ "L'",
572 \\ "F'",
573 \\};
574 \\
575 ,
576 \\const a = .{
577 \\ "U", "L", "F",
578 \\ "U'", "L'", "F'",
579 \\};
580 \\
581 );
582}
583
566584test "zig fmt: anon struct literal syntax" {
567585 try testCanonical(
568586 \\const x = .{
lib/std/zig/render.zig+6-6
......@@ -813,12 +813,10 @@ fn renderExpression(
813813 const expr_last_token = expr.*.lastToken() + 1;
814814 const next_expr = section_exprs[i + 1];
815815 const loc = tree.tokenLocation(tree.token_locs[expr_last_token].start, next_expr.*.firstToken());
816 if (loc.line == 0) {
817 column_counter += 1;
818 } else {
819 single_line = false;
820 column_counter = 0;
821 }
816
817 column_counter += 1;
818
819 if (loc.line != 0) single_line = false;
822820 } else {
823821 single_line = false;
824822 column_counter = 0;
......@@ -2655,6 +2653,8 @@ fn copyFixingWhitespace(ais: anytype, slice: []const u8) @TypeOf(ais.*).Error!vo
26552653 };
26562654}
26572655
2656// Returns the number of nodes in `expr` that are on the same line as `rtoken`,
2657// or null if they all are on the same line.
26582658fn rowSize(tree: *ast.Tree, exprs: []*ast.Node, rtoken: ast.TokenIndex) ?usize {
26592659 const first_token = exprs[0].firstToken();
26602660 const first_loc = tree.tokenLocation(tree.token_locs[first_token].start, rtoken);