Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Improve printing of callbacks in first arg position with comments #301

@IwanKaramazow

Description

@IwanKaramazow

https://forum.rescript-lang.org/t/weird-auto-code-formatting-with-pipe-first-operator/1189

Here is an example.

let foo = (fn, value) => fn(value)
let bar = (value, fn) => fn(value)

Two simple functions…one takes a function and value, the other, a value then function. Now here is where it gets weird. Say I want to pass an anonymous function, and put comments in there. It works fine with bar, and the -> operator:

let _ = 11->bar(x => {
  let y = 100

  // Do the addition.
  x + y
})

But the code formatter does weird things using foo:

// This is what I type....
// 11->foo(x => {
//   let y = 100

//   // Do the addition.
//   x + y
// }, _)

// But when the code formatter goes, this is what it "formats" to:
let _ = 11->foo(
  x => {
    let y = 100

    x + y
  },
  // Do the addition.

  _,
)

Note the comment gets shoved out of the function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions