Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Change style guide for conditional operators #1221

Closed
munificent opened this issue Jan 12, 2015 · 2 comments
Closed

Change style guide for conditional operators #1221

munificent opened this issue Jan 12, 2015 · 2 comments

Comments

@munificent
Copy link
Contributor

Based on discussions with the team and this public thread, we've decided to change the style guideline for conditional operators. Unlike other binary operators which stay on the previous line when a line break occurs near the operator, conditionals will go to the beginning of the next line, followed by a space.

I'll be changing the formatter to do this shortly.

Concretely, I think it means changing the style guide from:

DO place the operator on the preceding line in a multi-line expression.

To:

DO place binary operators on the preceding line in a multi-line expression.

And adding:

Do place ternary operators on the next line in a multi-line expression.

Also, if you break the line before one of the operators, prefer breaking around both.

// Bad:
return someCondition ?
    whenTrue : whenFalse;
return someCondition ?
    whenTrue :
    whenFalse;

// Good:
return someCondition
    ? whenTrue
    : whenFalse;
@kwalrath kwalrath self-assigned this Jan 14, 2015
@kwalrath
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants