reason icon indicating copy to clipboard operation
reason copied to clipboard

[refmt] Odd reformatting for side-effectful function and comment

Open leostera opened this issue 7 years ago • 1 comments

Input

{
  f(i);
  /* some comment here */
}

This is the smallest input I've seen replicate the behavior. I originally found this in a for loop.

Expected Output

The { } seem redundant, so I'd expect refmt to just remove them.

f(i);
/* some comment here */

Actual Output

f(
  i,
  /* some comment here */
);

Instead it seems to try to call f with more than a single parameter, which at first sight looks like it should be an error. From utop

utop # let f x = x;;
val f : 'a -> 'a = <fun>
utop # f(1,);;
Error: Syntax error: operator expected.

leostera avatar Jun 17 '18 09:06 leostera

I noticed while using bs-jest that the following code causes refmt issues:

describe("Foo", () => {
  test("success", () =>
    expect(true) |> toEqual(true)
  );
  test("success", () =>
    expect(false) |> toEqual(false)
  );
  /**
   * TODO: add more tests
   */
});

Removing the comment at the end of the block (or simply adding (); after the comment) fixes it. I'm not sure if this is the same issue... if not, I'm happy to open a new ticket.

mlms13 avatar Nov 05 '18 17:11 mlms13