reasonml / reasonml/reason

Printing too many parens for lambda:

Open
#1,711 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

let make = (~onClick, _children) => {
  ...component,
  reducer: (action, _state) =>
    switch action {
    | Click =>
      ReasonReact.UpdateWithSideEffects(nextState, (self => Js.log("leaf onClick triggered")))
    },
  didUpdate: self => Js.log("leaf updated (didUpdate)"),
  render: self => <div onClick=(e => self.send(Click))> (string("hello")) </div>
};
/* Compare the printed to desired */
ReasonReact.UpdateWithSideEffects(nextState, (self => Js.log("leaf onClick triggered")))

ReasonReact.UpdateWithSideEffects(nextState, self => Js.log("leaf onClick triggered"))

Interestingly, when refmt prints this on its own (not inside of a switch case), it omits the parens.

We should remove these parens to reduce paren-fatigue.

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

Start by reproducing the two snippets with refmt, comparing the output inside a switch case with the standalone output. Trace the formatter path responsible for lambda parentheses and confirm the unnecessary parentheses are removed without changing other formatting cases.

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.