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

Incorrect formatting when running ---fix for JSX with missing parentheses (jsx-wrap-multilines) #1382

Closed
jakefb opened this issue Aug 19, 2019 · 6 comments

Comments

@jakefb
Copy link

jakefb commented Aug 19, 2019

What version of this package are you using?

^14.0.0

What operating system, Node.js, and npm version?

macOS 10.14.5
node v12.8.0
npm 6.10.2

What happened?

It appears that jsx-wrap-multilines #710 has been implemented in standard v14, however when I run standard --fix the following happens.

Original code:

const Component = () =>
  <div>
    <p>Some text</p>
  </div>

export { Component as default }

Formatted code:

const Component = () => (
<div>
    <p>Some text</p>
  </div>
)export { Component as default }

What did you expect to happen?

I expected the export statement to be on a newline. Something strange is going on with the JSX formatting as well.

Are you willing to submit a pull request to fix this bug?

I could take a look into it and see if I can find what's causing the issue.

@feross
Copy link
Member

feross commented Aug 22, 2019

Sorry about the issue here. This is a bug in eslint-plugin-react. I opened an issue here: #1382

I'll temporarily disable this rule and release a new version of standard. We can re-enable this rule once the bug is fixed.

Note to self: re-add the following rule to eslint-config-standard-jsx when this bug is fixed:

    "react/jsx-wrap-multilines": ["error", {
      "declaration": "parens-new-line",
      "assignment": "parens-new-line",
      "return": "parens-new-line",
      "arrow": "parens-new-line",
      "condition": "parens-new-line",
      "logical": "ignore",
      "prop": "ignore"
    }],

feross added a commit to standard/eslint-config-standard-jsx that referenced this issue Aug 22, 2019
@feross
Copy link
Member

feross commented Aug 22, 2019

Released standard 14.0.1 with the fix.

@feross feross added the blocked label Aug 22, 2019
feross added a commit that referenced this issue Aug 22, 2019
I realized that without exact versions, we don't have to release a new version of standard when we relax a rule in one of the configs, like I just did for #1382

I would rather be forced to release a new version when I do this, so we have to add a changelog entry and document the change.
@jakefb
Copy link
Author

jakefb commented Aug 23, 2019

Thanks @feross, great work on the update by the way!

I have noticed something else strange which the parens-new-line condition when running standard --fix

Original code:

const Component = props => (
  <div>
    {true &&
      <div>
        <p>Some text</p>
      </div>
    }
  </div>
)

Formatted code:

const Component = props => (
  <div>
    {true &&
      <div>
        <p>Some text</p>
      </div>}
  </div>
)

I expected this to happen:

const Component = props => (
  <div>
    {true && (
      <div>
        <p>Some text</p>
      </div>
    )}
  </div>
)

Original code:

const Component = props => (
  <div>
    {true ?
      <div>
        <p>Some text</p>
      </div>
    : null}
  </div>
)

Formatted code:

const Component = props => (
  <div>
    {true
      ? <div>
        <p>Some text</p>
        </div>
      : null}
  </div>
)

I expected this to happen:

const Component = props => (
  <div>
    {true ? (
      <div>
        <p>Some text</p>
      </div>
    ) : null}
  </div>
)

@feross
Copy link
Member

feross commented Aug 23, 2019

@jakefb I agree with your expectations in the first example. As for the second example, we have a rule that ternary operators need to be at the start of the line, like this:

const x = condition
  ? 'true'
  : 'false

So when it comes to JSX, I guess it should format to this? But it's kind of terrible...

const Component = props => (
  <div>
    {true
      ? (
        <div>
          <p>Some text</p>
        </div>
      )
      : null}
  </div>
)

@jakefb
Copy link
Author

jakefb commented Aug 26, 2019

That makes sense. When writing plain JavaScript instead of JSX I think putting ternary operators on a newline makes the code more readable.

In my opinion when writing JSX it's more familiar to do it the same way as in the React docs because the formatting and indentation is similar to writing and if else tag in the Django template language or something similar.

@feross
Copy link
Member

feross commented Sep 4, 2019

The first issue you reported has been fixed upstream (but not in a release yet): #1382

The second two issues may still remain, though we should test it out.

@feross feross added this to the standard 16 milestone Oct 28, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants