rescript-lang / rescript-lang/rescript

switch-branch with multi-match branch is formatted weirdly

Open
#7,962 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

formatter
Dominant language
OCaml
Stars
7.5k
Forks
485
Avg merge
1d 2h
Merged PRs (30d)
55

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the switch expression and comments shown in the report, then trace the formatter path for multi-match switch branches. Add a regression case for this example and verify that formatting keeps the comments associated with the intended branches instead of moving them.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.