Skip to content

zig fmt: format switch according to whether it has a trailing comma #22258

@ghost

Description

Example:

    const exit_code: u8 = switch (state) { .success => 0, .failure => 1 };

In short examples like these I don't see the need to split it up into 4 lines like zig fmt would:

    const exit_code: u8 = switch (state) {
        .success => 0,
        .failure => 1,
    };

So the proposal is: let me define the formatting by putting or omitting the trailing comma after the last prong.

This behavior would also simply be more consistent with this behavior already existing with arrays, vectors, enums, structs, unions, function calls, function parameters, and maybe more.
Perhaps this is the only case like this with a list of things where the trailing comma is not respected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions