zig fmt: if condition has line break but must not wrap

This commit is contained in:
Andrew Kelley
2021-02-22 16:39:50 -07:00
parent b301999cd3
commit ec987a7a46
2 changed files with 27 additions and 29 deletions

View File

@@ -1410,31 +1410,31 @@ test "zig fmt: if condition wraps" {
\\
);
}
//
//test "zig fmt: if condition has line break but must not wrap" {
// try testCanonical(
// \\comptime {
// \\ if (self.user_input_options.put(
// \\ name,
// \\ UserInputOption{
// \\ .name = name,
// \\ .used = false,
// \\ },
// \\ ) catch unreachable) |*prev_value| {
// \\ foo();
// \\ bar();
// \\ }
// \\ if (put(
// \\ a,
// \\ b,
// \\ )) {
// \\ foo();
// \\ }
// \\}
// \\
// );
//}
//
test "zig fmt: if condition has line break but must not wrap" {
try testCanonical(
\\comptime {
\\ if (self.user_input_options.put(
\\ name,
\\ UserInputOption{
\\ .name = name,
\\ .used = false,
\\ },
\\ ) catch unreachable) |*prev_value| {
\\ foo();
\\ bar();
\\ }
\\ if (put(
\\ a,
\\ b,
\\ )) {
\\ foo();
\\ }
\\}
\\
);
}
//test "zig fmt: if condition has line break but must not wrap" {
// try testCanonical(
// \\comptime {

View File

@@ -1006,13 +1006,11 @@ fn renderWhile(ais: *Ais, tree: ast.Tree, while_node: ast.full.While, space: Spa
break :blk ident + 1;
}
};
const cond_has_newline = !tree.tokensOnSameLine(while_node.ast.while_token, pipe);
const brace_space: Space = if (cond_has_newline) .newline else .space;
const brace_space: Space = if (ais.isLineOverIndented()) .newline else .space;
try renderToken(ais, tree, pipe, brace_space); // |
} else {
const rparen = tree.lastToken(while_node.ast.cond_expr) + 1;
const cond_has_newline = !tree.tokensOnSameLine(while_node.ast.while_token, rparen);
const brace_space: Space = if (cond_has_newline) .newline else .space;
const brace_space: Space = if (ais.isLineOverIndented()) .newline else .space;
try renderToken(ais, tree, rparen, brace_space); // rparen
}
if (while_node.ast.cont_expr != 0) {