-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Print nested ternaries differently #5039
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
Print nested ternaries differently #5039
Conversation
? ddddddddddddddd | ||
: eeeeeeeeeeeeeee | ||
? fffffffffffffff | ||
: gggggggggggggggg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one seems not working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it
? "partially visible" | ||
: "hidden" | ||
? "partially visible" | ||
: "hidden" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 5 Input: a ? 1:2?1?3:4:2 Output: 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)