Skip to content
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

Add parenthesis for unusual nested ternaries #1386

Merged
merged 1 commit into from May 1, 2017

Conversation

vjeux
Copy link
Contributor

@vjeux vjeux commented Apr 22, 2017

All of the discussions around ternaries are for the form

cond1 ? elem1_if : cond2 ? elem2_if : elem_else

but some of them are for the form

cond1 ? cond2 ? elem2_if : elem2_else : elem1_else

which is more rare and would be good to call out by adding parenthesis.

cond1 ? (cond2 ? elem2_if : elem2_else) : elem1_else

Note that we only want parenthesis if it's written inline, otherwise the indentation is good enough to understand the flow:

cond1
  ? cond2 ? elem2_if : elem2_else
  : elem1_else

All of the discussions around ternaries are for the form

```js
cond1 ? elem1_if : cond2 ? elem2_if : elem_else
```

but some of them are for the form

```js
cond1 ? cond2 ? elem2_if : elem2_else : elem1_else
```

which is more rare and would be good to call out by adding parenthesis.

```js
cond1 ? (cond2 ? elem2_if : elem2_else) : elem1_else
```

Note that we only want parenthesis if it's written inline, otherwise the indentation is good enough to understand the flow:

```js
cond1
  ? cond2 ? elem2_if : elem2_else
  : elem1_else
```
@vjeux vjeux merged commit 314e963 into prettier:master May 1, 2017
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 20, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 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.

None yet

1 participant