zig fmt: Preserve trailing comma after single-item switch case
This commit is contained in:
committed by
Veikka Tuominen
parent
ab6317d32b
commit
3cafb9655a
@@ -2230,6 +2230,10 @@ test "zig fmt: switch cases trailing comma" {
|
||||
\\ 1,2,3 => {},
|
||||
\\ 4,5, => {},
|
||||
\\ 6... 8, => {},
|
||||
\\ 9 ...
|
||||
\\ 10 => {},
|
||||
\\ 11 => {},
|
||||
\\ 12, => {},
|
||||
\\ else => {},
|
||||
\\ }
|
||||
\\}
|
||||
@@ -2240,7 +2244,12 @@ test "zig fmt: switch cases trailing comma" {
|
||||
\\ 4,
|
||||
\\ 5,
|
||||
\\ => {},
|
||||
\\ 6...8 => {},
|
||||
\\ 6...8,
|
||||
\\ => {},
|
||||
\\ 9...10 => {},
|
||||
\\ 11 => {},
|
||||
\\ 12,
|
||||
\\ => {},
|
||||
\\ else => {},
|
||||
\\ }
|
||||
\\}
|
||||
|
||||
@@ -1894,9 +1894,6 @@ fn renderSwitchCase(
|
||||
// Render everything before the arrow
|
||||
if (switch_case.ast.values.len == 0) {
|
||||
try renderToken(r, switch_case.ast.arrow_token - 1, .space); // else keyword
|
||||
} else if (switch_case.ast.values.len == 1 and !has_comment_before_arrow) {
|
||||
// render on one line and drop the trailing comma if any
|
||||
try renderExpression(r, switch_case.ast.values[0], .space);
|
||||
} else if (trailing_comma or has_comment_before_arrow) {
|
||||
// Render each value on a new line
|
||||
try renderExpressions(r, switch_case.ast.values, .comma);
|
||||
|
||||
Reference in New Issue
Block a user