Skip to content

Prefer to split in || patterns in a switch expression instead of the value #1602

@munificent

Description

@munificent

Currently, the formatter formats the following switch expression case like so:

    return switch (_advance().type) {
      TokenType.float || TokenType.int || TokenType.string => LiteralExpression(
        _previous.value!,
      ),
    };

We already have special formatting for || patterns in a switch expression to make them look sort of like a series of fallthrough cases in a switch statement. Given that, I think it makes sense to also tweak the splitting costs so that it prefers to split on the || instead of in the case expression. That way, you get:

    return switch (_advance().type) {
      TokenType.float ||
      TokenType.int ||
      TokenType.string => LiteralExpression(_previous.value!),
    };

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions