mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 09:03:12 +00:00
zig fmt: fix idempotency with newlines surrounding doc comment
Fixes: https://github.com/ziglang/zig/issues/11802
This commit is contained in:
parent
8974cee5a1
commit
bb2929ba08
@ -4683,7 +4683,6 @@ pub const prctl_mm_map = extern struct {
|
||||
};
|
||||
|
||||
pub const NETLINK = struct {
|
||||
|
||||
/// Routing/device hook
|
||||
pub const ROUTE = 0;
|
||||
|
||||
|
@ -4154,6 +4154,41 @@ test "zig fmt: container doc comments" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: remove newlines surrounding doc comment" {
|
||||
try testTransform(
|
||||
\\
|
||||
\\
|
||||
\\
|
||||
\\/// doc comment
|
||||
\\
|
||||
\\fn foo() void {}
|
||||
\\
|
||||
,
|
||||
\\/// doc comment
|
||||
\\fn foo() void {}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: remove newlines surrounding doc comment within container decl" {
|
||||
try testTransform(
|
||||
\\const Foo = struct {
|
||||
\\
|
||||
\\
|
||||
\\ /// doc comment
|
||||
\\
|
||||
\\ fn foo() void {}
|
||||
\\};
|
||||
\\
|
||||
,
|
||||
\\const Foo = struct {
|
||||
\\ /// doc comment
|
||||
\\ fn foo() void {}
|
||||
\\};
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: anytype struct field" {
|
||||
try testError(
|
||||
\\pub const Pointer = struct {
|
||||
|
@ -2482,7 +2482,17 @@ fn renderDocComments(ais: *Ais, tree: Ast, end_token: Ast.TokenIndex) Error!void
|
||||
}
|
||||
const first_tok = tok;
|
||||
if (first_tok == end_token) return;
|
||||
try renderExtraNewlineToken(ais, tree, first_tok);
|
||||
|
||||
if (first_tok != 0) {
|
||||
const prev_token_tag = token_tags[first_tok - 1];
|
||||
|
||||
// Prevent accidental use of `renderDocComments` for a function argument doc comment
|
||||
assert(prev_token_tag != .l_paren);
|
||||
|
||||
if (prev_token_tag != .l_brace) {
|
||||
try renderExtraNewlineToken(ais, tree, first_tok);
|
||||
}
|
||||
}
|
||||
|
||||
while (token_tags[tok] == .doc_comment) : (tok += 1) {
|
||||
try renderToken(ais, tree, tok, .newline);
|
||||
|
Loading…
Reference in New Issue
Block a user