diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-12-10 23:26:38 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-12-11 02:34:44 -0500 |
| commit | fa6449dac06435175bee6113a0676ef2d43d777c (patch) | |
| tree | 5daa08b68b8294a108cfa1edb8e997524cade8f1 /lib | |
| parent | 64a590a31194a778b494937e2f91642b80e3f4d0 (diff) | |
| download | zig-fa6449dac06435175bee6113a0676ef2d43d777c.tar.gz zig-fa6449dac06435175bee6113a0676ef2d43d777c.zip | |
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
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/zig/parser_test.zig | 20 | ||||
| -rw-r--r-- | lib/std/zig/render.zig | 12 |
2 files changed, 25 insertions, 7 deletions
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index a526e1fa67..1205dbadab 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -286,7 +286,7 @@ test "zig fmt: respect line breaks after var declarations" { \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^ \\ lookup_tables[7][@truncate(u8, self.crc >> 0)]; \\ - ); + ); } test "zig fmt: multiline string mixed with comments" { @@ -563,6 +563,24 @@ test "zig fmt: anon literal in array" { ); } +test "zig fmt: alignment in anonymous literal" { + try testTransform( + \\const a = .{ + \\ "U", "L", "F", + \\ "U'", + \\ "L'", + \\ "F'", + \\}; + \\ + , + \\const a = .{ + \\ "U", "L", "F", + \\ "U'", "L'", "F'", + \\}; + \\ + ); +} + test "zig fmt: anon struct literal syntax" { try testCanonical( \\const x = .{ diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 3c026e5f21..f73979aa6b 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -813,12 +813,10 @@ fn renderExpression( const expr_last_token = expr.*.lastToken() + 1; const next_expr = section_exprs[i + 1]; const loc = tree.tokenLocation(tree.token_locs[expr_last_token].start, next_expr.*.firstToken()); - if (loc.line == 0) { - column_counter += 1; - } else { - single_line = false; - column_counter = 0; - } + + column_counter += 1; + + if (loc.line != 0) single_line = false; } else { single_line = false; column_counter = 0; @@ -2655,6 +2653,8 @@ fn copyFixingWhitespace(ais: anytype, slice: []const u8) @TypeOf(ais.*).Error!vo }; } +// Returns the number of nodes in `expr` that are on the same line as `rtoken`, +// or null if they all are on the same line. fn rowSize(tree: *ast.Tree, exprs: []*ast.Node, rtoken: ast.TokenIndex) ?usize { const first_token = exprs[0].firstToken(); const first_loc = tree.tokenLocation(tree.token_locs[first_token].start, rtoken); |
