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

Merged
merged 7 commits into from Oct 14, 2018

Conversation

Projects
None yet
5 participants
@suchipi
Member

suchipi commented Aug 31, 2018

Changes formatting of switch-style nested ternaries to the suggestion in #4767 (comment).

Fixes #737

  • I’ve added tests to confirm my change works.
  • (n/a) (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)
  • I’ve read the contributing guidelines.
? ddddddddddddddd
: eeeeeeeeeeeeeee
? fffffffffffffff
: gggggggggggggggg;

This comment has been minimized.

@ikatyang

ikatyang Sep 1, 2018

Member

This one seems not working.

@duailibe

I like it

? "partially visible"
: "hidden"
? "partially visible"
: "hidden"

This comment has been minimized.

@ikatyang

ikatyang Sep 4, 2018

Member

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.

This comment has been minimized.

@suchipi

suchipi Sep 4, 2018

Member

Ok, thanks. I will fix it. I appreciate the insight

@lydell

This comment has been minimized.

Collaborator

lydell commented Oct 13, 2018

@suchipi Do you think you’ll be able to finish this one up?

@duailibe

This comment has been minimized.

Member

duailibe commented Oct 13, 2018

@ikatyang Can you check if 23cc0cc fixed it?

@ikatyang

This comment has been minimized.

Member

ikatyang commented Oct 14, 2018

--use-tabs is working, but spaces are not.

Prettier pr-5039
Playground link

--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";

This comment has been minimized.

@ikatyang

ikatyang Oct 14, 2018

Member

Unrelated to this PR: We should force breaking nested TS type ternaries just like normal ternaries.

@suchipi

This comment has been minimized.

Member

suchipi commented Oct 14, 2018

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 ❤️

@duailibe duailibe merged commit 0fa34b2 into prettier:master Oct 14, 2018

10 checks passed

ci/circleci: build_prod Your tests passed on CircleCI!
Details
ci/circleci: checkout_code Your tests passed on CircleCI!
Details
ci/circleci: test_prod_node4 Your tests passed on CircleCI!
Details
ci/circleci: test_prod_node9 Your tests passed on CircleCI!
Details
ci/circleci: test_prod_standalone Your tests passed on CircleCI!
Details
codecov/patch 100% of diff hit (target 80%)
Details
codecov/project 96.38% (+0.01%) compared to c7093cb
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details
@duailibe

This comment has been minimized.

Member

duailibe commented Oct 14, 2018

Great work @suchipi and @ikatyang. Thank you!

@davidmccabe

This comment has been minimized.

davidmccabe commented Nov 5, 2018

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:

const value = condition1
? value1
: condition2
    ? value2
    : condition3
        ? value3
        : value4;

It's not clear why this example is formatted differently from the others. Is this intended?

@suchipi

This comment has been minimized.

Member

suchipi commented Nov 5, 2018

@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:

input
~~~~~~~~~
output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment