Weird formatting of long nested ternary expression
See original GitHub issueHi 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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:21 (12 by maintainers)
Top Results From Across the Web
javascript - A somewhat painful triple-nested ternary operator
If your JavaScript codebase contains nested ternary statements like the one in question, consider converting the formatting to daisy chained ternary ...
Read more >Use nested ternary operators without confusion with better ...
Fix this with a simple formatting trick that makes long, nested ternary operators easy to understand. Instead of: const foo = a ?...
Read more >Rethinking the JavaScript ternary operator - James Sinclair
With the ternary operator, the second and third expressions can be any type. But the interpreter will always cast the first to a...
Read more >I shall never give up on forcing ternary statements down my ...
But again, formatting probably matters the most. ... As long as it isn't nested I think ternary operator is fine and it depends...
Read more >Prettier 1.12: Fixes, Features, and Formatting, Oh My!
When ternaries are nested, depending on the print width and indentation level, sometimes the outer ternary could get broken across multiple ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sheerun , use the
"alignTernaryLines": false
in your prettierrc.jsonwith alignTernaryLines as
false
you have this output:The logic is the same as ESLint
indent.flatTernaryExpressions
So now the plan is as follows…
First eslint needs to merge PR I’ve prepared that introduces option for indent rule that fixes this issue: https://github.com/eslint/eslint/pull/12556
Then I need to convince standard to use this rule as default: https://github.com/standard/standard/issues/927
Finally I need to convince prettierx to change how
--no-align-ternary-line
works: https://github.com/brodybits/prettierx/issues/41