Print nested ternaries differently#5039
Conversation
| ? ddddddddddddddd | ||
| : eeeeeeeeeeeeeee | ||
| ? fffffffffffffff | ||
| : gggggggggggggggg; |
| ? "partially visible" | ||
| : "hidden" | ||
| ? "partially visible" | ||
| : "hidden" |
There was a problem hiding this comment.
This shouldn't be changed, we have a special case for ternary in ternary to use tabs in --use-tabs mode, that's what the removed part in 3018dd1 wanted to achieve.
Edit: I meant indent, not just tabs.
There was a problem hiding this comment.
Ok, thanks. I will fix it. I appreciate the insight
|
@suchipi Do you think you’ll be able to finish this one up? |
|
Prettier pr-5039 --parser babylon
--print-width 1
--tab-width 5Input: a ? 1:2?1?3:4:2Output: a
? 1
: 2
? 1
? 3
: 4
: 2;Expected Output a
? 1
: 2
? 1
? 3
: 4
: 2; |
| ? "boolean" | ||
| : T extends undefined | ||
| ? "undefined" | ||
| : T extends Function ? "function" : "object"; |
There was a problem hiding this comment.
Unrelated to this PR: We should force breaking nested TS type ternaries just like normal ternaries.
|
Thanks @ikatyang, my life has been really busy lately because I am getting a new job and my apartment got flooded, I really appreciate the help ❤️ |
|
This is a huge improvement, thanks for working on it. Looking at the test file, it seems that one of the examples is still not flattened, lines 5 – 11: It's not clear why this example is formatted differently from the others. Is this intended? |
|
@davidmccabe could you link the the file and line that you're looking at? It's possible that you're looking at the unformatted input. Our snapshots look like this: |
|
@suchipi / @ikatyang -- It looks like this PR implemented changes that led to this issue being opened: #5257 -- would somebody mind commenting in there to see if that issue should be instead marked as a "Won't-fix"/"Working as intended"? If this is the new way, and that issue isn't a bug so much as a stylistic preference that doesn't match with the changes introduced here, then I'll just deal. |
|
@fbartho that issue was open in Oct 12, this PR was only merged in Oct 14. These are probably unrelated |
Changes formatting of switch-style nested ternaries to the suggestion in #4767 (comment).
Fixes #737
docs/directory)