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

Can't seem to properly indent ? : statements #625

Closed
0x80 opened this issue Jun 6, 2016 · 11 comments
Closed

Can't seem to properly indent ? : statements #625

0x80 opened this issue Jun 6, 2016 · 11 comments

Comments

@0x80
Copy link

0x80 commented Jun 6, 2016

In our codebase we use quite a bit of this type of if/else rendering:

      {
          condition
          ? <div>
              <div> something </div>
            </div>
          : <div>
              <div> something </div>
            </div>
        }

Whatever indentation I try I always seem to get a jsx-indent error. Is there a way to format this without the linter complaining?

@yannickcr
Copy link
Member

Seems related to #540

@jonvuri
Copy link

jonvuri commented Oct 12, 2016

#540 has been closed - did it fix this? There was no test for it.

@ljharb
Copy link
Member

ljharb commented Oct 12, 2016

{condition ? (
  <div>
    <div> something </div>
  </div>
) : (
  <div>
    <div> something </div>
  </div>
)}

or

{condition
  ? (
    <div>
      <div> something </div>
    </div>
  )
  : (
    <div>
      <div> something </div>
    </div>
  )
}

?

@jonvuri
Copy link

jonvuri commented Oct 12, 2016

Neither -

{condition
  ? <div>
      <div> something </div>
    </div>
  : <div>
      <div> something </div>
    </div>
}

@ljharb
Copy link
Member

ljharb commented Oct 13, 2016

Right, I'm suggesting two forms that should satisfy the rule.

If those work, and your example doesn't, then it seems like an issue when parens are omitted.

@IanVS
Copy link

IanVS commented Dec 30, 2016

I would also love to be able to use:

condition
? <div>
     <div> something </div>
  </div>
: <div />

rather than

condition
? <div>
    <div> something </div>
</div>
: <div />

The closing is aligned to the opening tags, rather than the ? and :.

Would this be possible to add as an option?

@jonvuri
Copy link

jonvuri commented Jul 22, 2017

Is this ever going to get fixed? To this day, still have to keep jsx-indent turned off because this doesn't work as expected (or at least have an option).

@jonvuri
Copy link

jonvuri commented Jul 22, 2017

Made a new issue since @ljharb perhaps indicated it's an issue with lacking parens (but that seems like it should be a valid use case?).

@ljharb
Copy link
Member

ljharb commented Jul 23, 2017

To clarify, I think it should be a supported use case, but I don't think it's a good style :-)

@jonvuri
Copy link

jonvuri commented Jul 25, 2017

@ljharb Thanks for the clarification! That's good to hear. In your opinion should it be the default (when parens are omitted, that is) or an added option?

@ljharb
Copy link
Member

ljharb commented Jul 25, 2017

I think that the default should be identical when parens are omitted or not - iow, delete the parens out of #625 (comment) for the style without them.

The more compact style requested here should be an option (not the default)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants