reasonml / reasonml/reason

[refmt] Incorrect indentation when right side of pipe operator (|>) is multi-line

Open
#1,627 3 comments 1 reaction 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

Input:

m
|> StringMap.add("a", 1)
|> StringMap.fold_right(
  (el, m) => StringMap.add(el, 1, m),
  ["someReallyLongString"]
)
|> StringMap.add("h", 1);

Desired output:

m
|> StringMap.add("a", 1)
|> StringMap.fold_right(
    (el, m) => StringMap.add(el, 1, m),
    ["someReallyLongString"]
  )
|> StringMap.add("h", 1);

Actual output:

m
|> StringMap.add("a", 1)
|> StringMap.fold_right(
     (el, m) => StringMap.add(el, 1, m),
     ["someReallyLongString"]
   )
|> StringMap.add("h", 1);

It's bad that the indented lines are not tab-aligned. They have 5, 5, and 3 spaces in front.

Slightly relevant prettier example: https://goo.gl/6eXRLn

(Edit: No longer relevant comment) Less confident in the desired output because now the closing paren aligns with the |> operator. However prettier does support the JavaScript pipeline proposal and does alignment more similar to the desired output above: https://goo.gl/vvfTfb

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 running the supplied pipeline input through refmt and compare its indentation with the desired and actual outputs in the issue. Trace the formatter behavior for a multi-line right-hand side of the |>(pipe) operator; done means the inner lines are consistently indented and the closing parenthesis matches the stated desired output.

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.