Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recast inserts newlines for no reason #11

Open
nickretallack opened this issue Apr 5, 2020 · 1 comment
Open

Recast inserts newlines for no reason #11

nickretallack opened this issue Apr 5, 2020 · 1 comment
Labels
formatting Unexpected code formatting changes

Comments

@nickretallack
Copy link

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,
});
@danielo515
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatting Unexpected code formatting changes
Projects
None yet
Development

No branches or pull requests

3 participants