Skip to content

Commit

Permalink
Merge pull request #66 from nolanderc/formatting-array-literal
Browse files Browse the repository at this point in the history
properly indent initializer lists
  • Loading branch information
nolanderc authored Jul 31, 2024
2 parents b2a9313 + fcc0263 commit 5b9848b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/format.zig
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fn formatNode(tree: parse.Tree, current: usize, writer: anytype) !void {
try writer.emitLeadingWhitespace(writer.source.len, .{ .min = 1, .max = 1 });
},

.block, .field_declaration_list => {
.block, .field_declaration_list, .initializer_list => {
const children = tree.children(current);
var inside_block = false;
var has_children = false;
Expand Down Expand Up @@ -657,6 +657,20 @@ test "format multiline define" {
);
}

test "format multiline array literal" {
try expectIsFormatted(
\\const float data[] = {
\\ 0.0,
\\ 1.0,
\\ 2.0,
\\ 3.0,
\\ 4.0,
\\ 5.0,
\\ };
\\
);
}

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

0 comments on commit 5b9848b

Please sign in to comment.