reasonml / reason

Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
http://reasonml.github.io
MIT License
10.14k stars 428 forks source link

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

Closed denis-ok closed 2 months ago

denis-ok commented 8 months ago

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
  ()
};
anmonteiro commented 2 months ago

This has been considered a feature of Reason since the start, but personally it's always annoyed me.

I'm sure some folks depend on it, though, so not sure what to do about it.

anmonteiro commented 2 months ago

there's some discussion in https://github.com/reasonml/reason/issues/1700

anmonteiro commented 2 months ago

let's follow this in #1700