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

Open
jakefb opened this issue Aug 19, 2019 · 4 comments

Comments

@jakefb
Copy link

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

For configs, switch back to exact versions
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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Member

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>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.