mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
zig fmt: fix extra whitespace in StructInit with multiline strings
68d2f68ed introduced special handling for StructInit fields
containing multiline strings to prevent inserting whitespace after =.
However, this logic didn't handle cases without a trailing comma,
which resulted in unwanted trailing whitespace.
This commit is contained in:
parent
a6d444c271
commit
26db54d69b
4 changed files with 102 additions and 91 deletions
|
|
@ -2056,7 +2056,8 @@ fn renderStructInit(
|
||||||
const init_token = tree.firstToken(field_init);
|
const init_token = tree.firstToken(field_init);
|
||||||
try renderToken(r, init_token - 3, .none); // .
|
try renderToken(r, init_token - 3, .none); // .
|
||||||
try renderIdentifier(r, init_token - 2, .space, .eagerly_unquote); // name
|
try renderIdentifier(r, init_token - 2, .space, .eagerly_unquote); // name
|
||||||
try renderToken(r, init_token - 1, .space); // =
|
const space_after_equal: Space = if (tree.nodeTag(field_init) == .multiline_string_literal) .none else .space;
|
||||||
|
try renderToken(r, init_token - 1, space_after_equal); // =
|
||||||
try renderExpressionFixup(r, field_init, .comma_space);
|
try renderExpressionFixup(r, field_init, .comma_space);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5719,6 +5719,16 @@ test "zig fmt: no space before newline before multiline string" {
|
||||||
\\ ,
|
\\ ,
|
||||||
\\ };
|
\\ };
|
||||||
\\ _ = s2;
|
\\ _ = s2;
|
||||||
|
\\ const s3 = .{ .text =
|
||||||
|
\\ \\hello
|
||||||
|
\\ \\world
|
||||||
|
\\ , .comment = "test" };
|
||||||
|
\\ _ = s3;
|
||||||
|
\\ const s4 = .{ .comment = "test", .text =
|
||||||
|
\\ \\hello
|
||||||
|
\\ \\world
|
||||||
|
\\ };
|
||||||
|
\\ _ = s4;
|
||||||
\\}
|
\\}
|
||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue