Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig fmt: Fix formatting of if expressions #21703

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/std/zig/render.zig
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
try renderToken(r, main_token, after_op_space); // catch keyword
}

ais.pushIndentOneShot();
ais.pushIndent();
try renderExpression(r, datas[node].rhs, space); // fallback
ais.popIndent();
},

.field_access => {
Expand Down Expand Up @@ -564,8 +565,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
try renderToken(r, op_token, .newline);
ais.popIndent();
}
ais.pushIndentOneShot();
return renderExpression(r, infix.rhs, space);
ais.pushIndent();
try renderExpression(r, infix.rhs, space);
ais.popIndent();
},

.assign_destructure => {
Expand Down Expand Up @@ -594,8 +596,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
try renderToken(r, full.ast.equal_token, .newline);
ais.popIndent();
}
ais.pushIndentOneShot();
return renderExpression(r, full.ast.value_expr, space);
ais.pushIndent();
try renderExpression(r, full.ast.value_expr, space);
ais.popIndent();
},

.bit_not,
Expand Down Expand Up @@ -725,8 +728,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {

.grouped_expression => {
try renderToken(r, main_tokens[node], .none); // lparen
ais.pushIndentOneShot();
ais.pushIndent();
try renderExpression(r, datas[node].lhs, .none);
ais.popIndent();
return renderToken(r, datas[node].rhs, space); // rparen
},

Expand Down Expand Up @@ -1243,8 +1247,9 @@ fn renderVarDeclWithoutFixups(
try renderToken(r, eq_token, eq_space); // =
ais.popIndent();
}
ais.pushIndentOneShot();
return renderExpression(r, var_decl.ast.init_node, space); // ;
ais.pushIndent();
try renderExpression(r, var_decl.ast.init_node, space); // ;
ais.popIndent();
}

fn renderIf(r: *Render, if_node: Ast.full.If, space: Space) Error!void {
Expand Down