mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 00:26:57 +00:00
parent
4a08c6dd51
commit
10e11b60e5
@ -5057,6 +5057,21 @@ test "zig fmt: make single-line if no trailing comma" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: preserve container doc comment in container without trailing comma" {
|
||||
try testTransform(
|
||||
\\const A = enum(u32) {
|
||||
\\//! comment
|
||||
\\_ };
|
||||
\\
|
||||
,
|
||||
\\const A = enum(u32) {
|
||||
\\ //! comment
|
||||
\\ _,
|
||||
\\};
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: make single-line if no trailing comma" {
|
||||
try testCanonical(
|
||||
\\// Test trailing comma syntax
|
||||
|
@ -1933,12 +1933,15 @@ fn renderContainerDecl(
|
||||
break :one_line;
|
||||
}
|
||||
|
||||
// 2. A member of the container has a doc comment.
|
||||
// 2. The container has a container comment.
|
||||
if (token_tags[lbrace + 1] == .container_doc_comment) break :one_line;
|
||||
|
||||
// 3. A member of the container has a doc comment.
|
||||
for (token_tags[lbrace + 1 .. rbrace - 1]) |tag| {
|
||||
if (tag == .doc_comment) break :one_line;
|
||||
}
|
||||
|
||||
// 3. The container has non-field members.
|
||||
// 4. The container has non-field members.
|
||||
for (container_decl.ast.members) |member| {
|
||||
if (!node_tags[member].isContainerField()) break :one_line;
|
||||
}
|
||||
@ -2358,7 +2361,7 @@ fn renderSpace(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex, lexeme_len: us
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if there exists a comment between any of the tokens from
|
||||
/// Returns true if there exists a line comment between any of the tokens from
|
||||
/// `start_token` to `end_token`. This is used to determine if e.g. a
|
||||
/// fn_proto should be wrapped and have a trailing comma inserted even if
|
||||
/// there is none in the source.
|
||||
|
Loading…
Reference in New Issue
Block a user