syntax
syntax copied to clipboard
Improve printing of callbacks in first arg position with comments
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.