Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

formatting for "if - else - if" #122

Closed
MyDogTom opened this issue Dec 6, 2017 · 1 comment · Fixed by #125
Closed

formatting for "if - else - if" #122

MyDogTom opened this issue Dec 6, 2017 · 1 comment · Fixed by #125

Comments

@MyDogTom
Copy link
Contributor

MyDogTom commented Dec 6, 2017

Ktlint allows the following formatting

fun funA() {
    if (conditionA()) {
        doSomething()
    } else 
    if (conditionB()) {
        doAnotherThing()
    }
}

there is real example

From my point of view, such formatting is a bit confusing (second if can be perceived as completely independent)

Proposal 1
Forbid line break between else and if

fun funA() {
    if (conditionA()) {
        doSomething()
    } else if (conditionB()) {
        doAnotherThing()
    }
}

Proposal 2 (doesn't make sense, if first proposal is accepted)
Teach indentionRule to enforce indent after else

fun funA() {
    if (conditionA()) {
        doSomething()
    } else
        if (conditionB()) {
            doAnotherThing()
        }
}

Personally, I would prefer the first one. I'm happy to implement it, if such PR is welcome.

@shyiko
Copy link
Collaborator

shyiko commented Dec 6, 2017

First proposal looks reasonable (and consistent with https://android.github.io/kotlin-guides/style.html examples).

Go ahead (and thank you 🙇‍♂️).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants