-
Notifications
You must be signed in to change notification settings - Fork 44
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
Weird formatting of long nested ternary expression #76
Comments
This would be solved after brodycj/prettierx#44 is fixed |
I hope to resolve it soon, no promises right now. |
Any updates? still broken. |
I think @brodybits removed this issue from prettierx but it still needs to be fixed there. If anyone would like to see it fixed, please controbute to prettierx repository |
The issue was moved to brodycj/prettierx#13 (original repository was renamed, issue was transferred, but link did not seem to redirect). And I think the issue was already fixed by @aMarCruz. @sheerun, I think this repo needs to use a newer version of |
@brodybits Good to know, I'll try to upgrade this repo |
@sheerun , use the with alignTernaryLines as The logic is the same as ESLint |
Ternary expressions should be fine in 10.0.0 |
Hmm I need to revert because there are unexpected issues with other syntax |
Here's an example how prettier-standard formats right now: const Component = () => (
<ul className='has-text-centered'>
{landmarks.hits.length > 0
? landmarks.hits.map(({ name, objectID }) => (
<li key={name}>
<a href={`${process.env.DOMAIN}` + `/city/${objectID}`}>{name}</a>
</li>
))
: null}
</ul>
) And here's how after fixing ternary expressions: const Component = () => (
<ul className='has-text-centered'>
{landmarks.hits.length > 0
? landmarks.hits.map(({ name, objectID }) => (
<li key={name}>
<a href={`${process.env.DOMAIN}` + `/city/${objectID}`}>{name}</a>
</li>
))
: null}
</ul>
) As you can see there's missing indent even though there's no second ternary expression. |
This comment has been minimized.
This comment has been minimized.
@sheerun It's the same result as current version of |
Should be. I based my PR on the ESLint rule code, which is the one that Standard uses. |
I'm sorry that this issue is this deep, but I think it should be fixed in standard first. Nested ternary expressions are far less common than single ternary with JSX code or map (as shown above) and I think this change would make formatting less readable. Formatting my project which this change re-formats tenths of files where nested ternary is not used. |
Here is another example of inconsistent formatting: standard --fix const Component = () => (
<ul className='has-text-centered'>
{landmarks.hits.length > 0
? landmarks.hits.map(({ name, objectID }) => {
return someverylongvariablelololololololololololololololol
}).map(({ name, objectID }) => {
return <foo />
})
: null}
</ul>
) But similar code with const Component = () => (
<ul className='has-text-centered'>
{landmarks.hits.length > 0
? landmarks.hits
.map(({ name, objectID }) => {
return someverylongvariablelololololololololololololololol
}).map(({ name, objectID }) => {
return <foo />
})
: null}
</ul>
) On the other hand currently prettier-standard formats both examples consistently (it doesn't matter where .map is): const Component = () => (
<ul className='has-text-centered'>
{landmarks.hits.length > 0
? landmarks.hits
.map(({ name, objectID }) => {
return someverylongvariablelololololololololololololololol
})
.map(({ name, objectID }) => {
return <foo />
})
: null}
</ul>
) |
Also, here's original example formatted with const Component = () => (
<ul className='has-text-centered'>
{landmarks.hits.length > 0
? landmarks.hits
.map(({ name, objectID }) => (
<li key={name}>
<a href={`${process.env.DOMAIN}` + `/city/${objectID}`}>{name}</a>
</li>
))
: null}
</ul>
) |
@sheerun any update on this? |
No, someone needs to fix this at prettierx |
We already made a fix before, see brodycj/prettierx#13. In case of troubles, someone please raise a new issue in https://github.com/brodybits/prettierx/issues with a minimal, reproducible example ([1]). [1] https://stackoverflow.com/help/minimal-reproducible-example |
I've described issue in more detail in brodycj/prettierx#41 So in short probably standard.js would need to be convinced first to make this change... |
So now the plan is as follows...
|
Hi
prettier standard formats my ternary expression without indent when breaking a line that is too long. This does not seem correct.
The simplified code snippet looks as follows:
When formatted it looks like this:
My only config is:
{ "printWidth": 120 }
Regards
The text was updated successfully, but these errors were encountered: