Skip to content

fix(javascript): indentation for sub-ternaries - #3747

Merged
ikatyang merged 5 commits into
prettier:masterfrom
ikatyang:fix/javascript-ternaries-sub-indent
Jan 16, 2018
Merged

ikatyang merged 5 commits into
prettier:masterfrom
ikatyang:fix/javascript-ternaries-sub-indent

Conversation

@ikatyang

@ikatyang ikatyang commented Jan 15, 2018 •

Copy link
Copy Markdown
Member

Fixes #3384

Only affects tabWidth > 2.


Prettier pr-3747
Playground link

--print-width 40
--tab-width 4

Input:

const Foo = () => (
    <div>
        {foo === null
            ? ""
            : foo === true
              ? "Yes"
              : "No"}
    </div>
);

Output:

const Foo = () => (
    <div>
        {foo === null
            ? ""
            : foo === true
                ? "Yes"
                : "No"}
    </div>
);

Comment thread tests/ternaries/indent.js
@@ -1 +1,15 @@
aaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb : ccccccccccccccc ? ddddddddddddddd : eeeeeeeeeeeeeee ? fffffffffffffff : gggggggggggggggg

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could set printWidth: 40 instead of very long strings.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll cause unnecessary diffs, I think it'd be better to not touch unrelated snapshots?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's true.

};
a => (a ? a : a);
a =>
a ? aasdasdasdasdasdasdaaasdasdasdasdasdasdasdasdasdasdasdasdasdaaaaaa : a;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there just one space at the start of this line?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 tab, it's the current behavior.

You can see 37b2ece for actual changes related to this PR.

run_spec(__dirname, ["flow", "typescript"]);
run_spec(__dirname, ["flow", "typescript"], { tabWidth: 4 });
run_spec(__dirname, ["flow", "typescript"], { useTabs: true });
run_spec(__dirname, ["flow", "typescript"], { useTabs: true, tabWidth: 4 });

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually want to test tabWidth: 4, not sure why I wrote 2 originally...

@ikatyang
ikatyang merged commit 2dd311d into prettier:master Jan 16, 2018
@ikatyang
ikatyang deleted the fix/javascript-ternaries-sub-indent branch January 16, 2018 03:32
robert-j-webb pushed a commit to robert-j-webb/prettier that referenced this pull request Jan 18, 2018
* test: add test cases

* test: add test cases

* fix(javascript): indentation for sub-ternaries

* test: update test cases

* fix: no extra tab for `tabWidth: 4`
@lock lock Bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 18, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants