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

JSX ternaries with parens indent oddly #53

Closed
suchipi opened this issue Jan 10, 2017 · 3 comments
Closed

JSX ternaries with parens indent oddly #53

suchipi opened this issue Jan 10, 2017 · 3 comments
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Comments

@suchipi
Copy link
Member

suchipi commented Jan 10, 2017

I often use parens with JSX ternaries to align opening and closing blocks, so that each "if" or "child" indentation is just one more indentation level deep:

prettier, like many AST-based JSX formatters, strips the parens and moves the opening tag of each JSX element up to where the paren was, which looks weird:

@jlongster
Copy link
Member

Yep, I'm not sure if we'll get it 100% to the original example, but I agree that it looks better. JSX still needs several tweaks.

@suchipi
Copy link
Member Author

suchipi commented Jan 10, 2017

It's a bit difficult to detect when to do this because the AST doesn't consider parens as their own node. But maybe we could try to apply it in situations where it's most common, like ternaries, arrow function expressions, etc.

Here's an example of it in arrow function expressions:

<Something>
  {() => (
    <SomethingElse>
      <span />
    </SomethingElse>
  )}
</Something>

prettier currently outputs:

<Something>
  {() => <SomethingElse>
      <span />
    </SomethingElse>}
</Something>;

Edit: I hit submit before fixing my english 😅

@vramana
Copy link

vramana commented Jan 11, 2017

This is closely related to #73. So I am closing this in favour of that issue. You can file a new bug or reopen this if the problem still exists after that issue is solved.

@vramana vramana closed this as completed Jan 11, 2017
@suchipi suchipi mentioned this issue Jan 12, 2017
11 tasks
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 8, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests

3 participants