Skip to content
This repository has been archived by the owner on Oct 16, 2018. It is now read-only.

Be concrete about && and || at the beginning or end of a line #62

Open
vRallev opened this issue Apr 9, 2018 · 3 comments
Open

Be concrete about && and || at the beginning or end of a line #62

vRallev opened this issue Apr 9, 2018 · 3 comments

Comments

@vRallev
Copy link

vRallev commented Apr 9, 2018

I think Java prefers

if (condition1
    && condition 2
    || condition3) {

    // do something
}

This style would make sense to me in Kotlin as well, but I couldn't find anything regarding to that in the IJ Kotlin style guide or Android style guide. Note that there has been some discussion going on in the ktlint project what prefers

if (condition1 &&
    condition2 ||
    condition3) {

    // do something
}

pinterest/ktlint#168

@JakeWharton
Copy link
Contributor

Tragically (in my opinion), Kotlin forces you into the latter as otherwise things like

foo
+ bar

could be interpreted as

foo
unaryPlus(bar)

depending on what is in scope.

I thought we covered this somewhere but perhaps it was left ambiguous. Would be good to include.

@JakeWharton
Copy link
Contributor

That example doesn't actually apply to the binary boolean operators, but I see no reason to create archaic rules around which binary operators and types you're operating on so we'll normalize to end-of-line rather than start-of-line.

@vRallev
Copy link
Author

vRallev commented Apr 9, 2018

I agree that it's really sad. At least I have something else besides ktlint that I could reference. Thanks

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

No branches or pull requests

2 participants