-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Here is how Prettier currently reformats nested ternaries:
const value = condition1
? value1
: condition2
? value2
: condition3
? value3
: value4;
This isn't so bad when there are only two ternaries, but I sometimes have many more because I essentially use them as an alternative to a switch statement when each case only gets a single value.
Here is how I prefer to format this case:
const value =
condition1 ? value1 :
condition2 ? value2 :
condition3 ? value3 :
value4;
I like this because it clearly associates each condition with its corresponding value and the indentation doesn't increase regardless of the number of ternaries.
Perhaps some like the current formatting because it discourages use of nested ternaries, but I think my example shows that you can have any number without making the code hard to read.
Would you consider adding an option to support this alternate formatting? Maybe something like this? --ternary=condval