flowts icon indicating copy to clipboard operation
flowts copied to clipboard

Recast inserts newlines for no reason

Open nickretallack opened this issue 5 years ago • 1 comments

Commands run with --no-prettier

before/after JSX property

Input:

// @flow
({
  a,
  b: (
    <></>
  ),
  c,
});

Output with recast:

({
  a,

  b: (
    <></>
  ),

  c
});

Output with --no-recast

({
  a,
  b: <></>,
  c
});

But if the input looks like this, the output with recast is the same as above:

// @flow
({
  a,
  b: <></>,
  c,
});

before/after object literal property

Input:

// @flow
({
  a,
  b: {
    c,
  },
  c,
})

Output with recast:

({
  a,

  b: {
    c,
  },

  c
});

Output with --no-recast:

({
  a,
  b: {
    c
  },
  c
});

But if the input looks like this:

// @flow
({
  a,
  b: {c},
  c,
})

Then the output with recast looks like this:

({
  a,
  b: {c},
  c
});

While the output with --no-recast continues to look like this:

({
  a,
  b: {
    c
  },
  c
});

before/after comment

Input:

// @flow
({
  a,
  // comment
  b,
  c,
});

Output with recast:

({
  a,

  // comment
  b,

  c
});

Output with --no-recast:

({
  a,
  // comment
  b,
  c
});

If the input is:

// @flow
({
  a,
  b, // comment
  c,
})

Then the output with recast is still:

({
  a,

  // comment
  b,

  c
});

Though the output with --no-recast is different:

({
  a,
  b,
  // comment
  c
});

before/after interesting indentation

Input:

// @flow
({
  a,
  b:
    x,
  c,
});

Output with recast:

({
  a,

  b:
    x,

  c
});

Output without recast:

({
  a,
  b: x,
  c
});

But if the input is:

// @flow
({
  a,
  b: x,
  c,
});

Then the output with and without recast is the same:

({
  a,
  b: x,
  c
});

It seems like the rule is that if a property takes more than one line, including just because it has a comment, recast will reserve two extra lines for it.

This also triggers the problem:

// @flow
({
  a,
  b: [
  ],
  c,
});

But this doesn't:

// @flow
({
  a,
  b: [],
  c,
});

nickretallack avatar Apr 05 '20 22:04 nickretallack

If you ever find a solution to this, please ping me

danielo515 avatar Jun 12 '21 15:06 danielo515