Union probably formatted incorrectly

so my problem is that in the latest dev release at the time of writing, 0.12.0-dev.47+0461a64a9
zig fmt formats unions in a way that is really annoying to read

this is how unions get formatted on my computer

const UnionExample = union(enum) { field1, field2, field3: Type };

while the much more readable option would be

const UnionExample = union(enum) {
    field1,
    field2,
    field3: Type
};

is there a reason this is the case? because doing it like the second example would be much more friendly to look at.

the second example is also the case for untagged unions, but not for enums, or anything else that has multiple items in it, like functions, enums, structs, or everything else, so this could also help code consistency.

Put a comma after the last field and it will format it in the desired way:

const UnionExample = union(enum) {
    field1,
    field2,
    field3: Type,
};
2 Likes

thank you very much, I appreciate it!

1 Like

I have changed the category of this topic and marked the answer by @IntegratedQuantum to be the solution.

Also, welcome @martijn_t to the forums :slight_smile: