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 multi-line ternary operator indentation #521

Closed
tvervest opened this issue May 16, 2016 · 3 comments

Comments

@tvervest
Copy link

commented May 16, 2016

I ran into this issue while working with React views and ternary operators. If the react element is multi-lined, I wrap it in parentheses and put the element itself on an indented newline, for better readability.

However, when I do this I get a warning on the opening li tag, stating Expected indentation of 8 space characters, but found 10. (react/jsx-indent). Shouldn't this be correct? It seems very strange to me that the li element should be on the same depth as the ? character of the ternary operator.

Example:
Incorrect (according to standard):

const myElement = (
  <ul>
    {
      showX
        ? (
          <li>
            <h3>Value of X:</h3>
            <p>{x}</p>
          </li>
        )
        : null
    }
  </ul>
)

Correct (according to standard):

const myElement = (
  <ul>
    {
      showX
        ? (
        <li>
          <h3>Value of X:</h3>
          <p>{x}</p>
        </li>
        )
        : null
    }
  </ul>
)
@feross

This comment has been minimized.

Copy link
Member

commented May 16, 2016

This looks like a bug in eslint-plugin-react. Can you re-open this issue there?

@feross feross closed this May 16, 2016

@tvervest

This comment has been minimized.

Copy link
Author

commented May 17, 2016

Ah, you're right. Linking in yannickcr/eslint-plugin-react#454 for future reference.

@feross

This comment has been minimized.

Copy link
Member

commented May 17, 2016

Cool, thanks for sharing that link.

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
2 participants
You can’t perform that action at this time.