reasonml / reasonml/reason

refmt does not preserve original placing of comments

Open
#1,696 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

KIND: BUG Printer
Dominant language
OCaml
Stars
10.3k
Forks
438
PR merge metrics
No merged PRs in 30d

Description

In the below snippet NewListener and RemoveListener are both above /* Stream events */.

  [@bs.send.pipe : T.t]
  external on :
    (
    [@bs.string]
    [
      /* EventEmitter events */
      [@bs.as "newListener"]
      | `NewListener((string, 'any) => unit)
      [@bs.as "removeListener"] | `RemoveListener((string, 'any) => unit)
      /* Stream events */
      /* Readable Stream events */
      [@bs.as "close"] | `Close(unit => unit)
      [@bs.as "error"] | `Error(Error.t => unit)
      [@bs.as "data"] | `Data(Node.string_buffer => unit)
      [@bs.as "end"] | `End(unit => unit)
      [@bs.as "readable"] | `Readable(unit => unit)
    ]
    ) =>
    T.t =
    "";

It gets formatted as:

  [@bs.send.pipe : T.t]
  external on :
    (
    [@bs.string]
    [
      /* EventEmitter events */
      [@bs.as "newListener"]
      | `NewListener((string, 'any) => unit)
      /* Stream events */
      /* Readable Stream events */
      [@bs.as "removeListener"] | `RemoveListener((string, 'any) => unit)
      [@bs.as "close"] | `Close(unit => unit)
      [@bs.as "error"] | `Error(Error.t => unit)
      [@bs.as "data"] | `Data(Node.string_buffer => unit)
      [@bs.as "end"] | `End(unit => unit)
      [@bs.as "readable"] | `Readable(unit => unit)
    ]
    ) =>
    T.t =
    "";

RemoveListener gets pushed below /* Stream events */ and /* Readable Stream events */.

Contributor guide

No contributing guide indexed for this repository

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

Run refmt on the Reason snippet in the issue and compare the output with the original comment positions. Trace the formatter behavior responsible for comments around the variant cases. Done means refmt preserves the placement of both Stream events comments while continuing to format the surrounding code correctly.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.