Skip to content

Commit

Permalink
better formatting for parens and array indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanderc committed Oct 31, 2023
1 parent f161adc commit 496a145
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/format.zig
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ fn formatNode(tree: parse.Tree, current: usize, writer: anytype) !void {
.array,
.array_specifier,
.selection,
.parenthized,
=> {
const children = tree.children(current);
for (children.start..children.end) |child| {
Expand Down Expand Up @@ -370,7 +371,6 @@ fn needsLeadingSpace(tag: parse.Tag) bool {
.@",",
.parameter_list,
.array,
.array_specifier,
=> false,
else => true,
};
Expand Down Expand Up @@ -590,6 +590,33 @@ test "format ternary condition" {
);
}

test "format parenthized" {
try expectIsFormatted(
\\void main() {
\\ int foo = (1 + 1);
\\}
\\
);
}

test "format assign array" {
try expectIsFormatted(
\\void main() {
\\ int foo = bar[123];
\\}
\\
);
}

test "format array declaration" {
try expectIsFormatted(
\\void main() {
\\ int[2] foo[123];
\\}
\\
);
}

fn expectIsFormatted(source: []const u8) !void {
try expectFormat(source, source);
}
Expand Down

0 comments on commit 496a145

Please sign in to comment.