rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

switch-branch with multi-match branch is formatted weirdly

Open tx46 opened this issue 2 months ago • 2 comments

switch 0 {
  // Something something
  | 0
  // Another something
  | 1 =>
    let foo = 123
    doSomethingInteresting(foo)
}

formats to:

switch 0 {
// Something something
| 0
| // Another something
1 =>
  let foo = 123
  doSomethingInteresting(foo)
}

which likely doesn't match the intention here. in general i dislike that the formatter is throwing my comments around and won't let me place them as i want to.

tx46 avatar Oct 14 '25 02:10 tx46

as an added bonus, it's takes multiple formats to make this stable:

switch 0 {
| 0 // Something something
| 1 // Another something
=>
  let foo = 123
  doSomethingInteresting(foo)
}

format once:

switch 0 {
| 0 // Something something
| 1 => // Another something
  let foo = 123
  doSomethingInteresting(foo)
}

format twice:

switch 0 {
| 0 // Something something
| 1 =>
  // Another something
  let foo = 123
  doSomethingInteresting(foo)
}

tx46 avatar Oct 14 '25 02:10 tx46

Thanks for reporting this, we should probably keep track of the | in Ppat_or and attach the comment accordingly.

nojaf avatar Oct 20 '25 08:10 nojaf