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

Pattern-matching of bool value is formatted to ternary if we match true first #2733

Open
denis-ok opened this issue Jan 24, 2024 · 0 comments

Comments

@denis-ok
Copy link

denis-ok commented Jan 24, 2024

When pattern-matching boolean values, it's common to match the true value first. However, this approach can lead to undesirable formatting behavior. For instance:

This:

switch (condition) {
| true => ()
| false => ()
};

Formats to:

condition ? () : ();

Sometimes a code style when we first match a shorter branch (with less code) is preferred.
To prevent automatic formatting to a ternary expression in such cases we have to match false as a wildcard _false.

switch (condition) {
| true =>
  // short code
  ()
| _false => 
  // long code
  // long code
  // long code
  ()
};
@denis-ok denis-ok changed the title Pattern-matching of bool value formats to ternary if we match true first Pattern-matching of bool value is formatted to ternary if we match true first Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant