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
No way to format ternary JSX expressions? #1564
Comments
Agreed – this is a bug. Working on a fix. |
Fixed in 15.0.1. |
Duplicate of standard/eslint-config-standard#177 |
With import * as React from 'react'
export const y = new Date().getTime() % 2
? (
<span>
ghi
</span>
)
: 'jkl' Thank you for the prompt fix! We are now unblocked. 🚀 (Although, subjectively, I think this formatting looks rather strange.) |
@s100 Great! What formatting would you prefer? |
Thanks for asking! My preferred formatting would be: export const y = new Date().getTime() % 2
? (
<span>
ghi
</span>
)
: 'jkl' The reason I prefer this is:
This is consistent with other bracketed forms in Standard:
See here how, likewise:
|
@s100 Right now the reason that it's formatted this way is because of the I think that ideally, we'd make an exception to this rule when an expression wrapped in parens appears as the value in the ternary expression, as it does in your example. In that case, I think indenting as you have done makes the most sense. Unfortunately, there's no |
To be honest I think the best solution is to leave in standard config just linting rules, and use prettierx for formatting in |
btw. This probably should read: export const y = new Date().getTime() % 2
? (
<span>
ghi
</span>
)
: 'jkl' but parens are not really necessary: export const y = new Date().getTime() % 2
? <span>
ghi
</span>
: 'jkl' |
@sheerun Hah, I entirely agree that the parentheses should be unnecessary but that's been impossible since at least import * as React from 'react'
export const y = new Date().getTime() % 2
? <span>
ghi
</span>
: 'jkl'
import * as React from 'react'
export const y = new Date().getTime() % 2
? <span>
ghi
</span>
: 'jkl'
import * as React from 'react'
export const y = new Date().getTime() % 2
? <span>
ghi
</span>
: 'jkl'
We added parentheses everywhere because there was no other way we could figure out to keep Standard happy. Starting from
|
What version of this package are you using?
standard@15.0.0
witheslint@7.11.0
What operating system, Node.js, and npm version?
Windows 10, Node.js 10.17.0, npm 6.11.3
What happened?
Here's my source file:
Standard gives me:
OK so it looks like the second expression in a ternary needs a little extra indentation. I'll fix my test file:
Standard now gives me:
If I use
--fix
, Standard changes my code to look like this:which doesn't look right, and, Standard still gives me errors:
What did you expect to happen?
At least one of these code samples should be considered correct by Standard. Or, if there's an alternate correct formatting which I'm missing, I would be interested to know what it is.
Are you willing to submit a pull request to fix this bug?
No. I wouldn't know where to start.
The text was updated successfully, but these errors were encountered: