Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
munificent opened this issue Nov 15, 2024 · 0 comments

Comments

@munificent
Copy link
Member

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!),
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant