Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
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

Description

@munificent

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;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions