Ktlint: Line wrap for &&

Created on 6 Mar 2018  路  8Comments  路  Source: pinterest/ktlint

I've seen f13b93e and probably because of that my code is wrong. My snippet looks like this

            .assertValueAt(2) {
                it is ImageChangeEvent.ImageUpdated
                        && it.position == 0
                        && it.changedFields.contains(CollectImage.IMAGE_MODE)
                        && it.image.imageMode == newImageMode
            }

Kotlin Lint complaints with Line must not begin with "&&". I couldn't find anything regarding that in the Kotlin style guide and to me this rule seems wrong. Can you point me to the rule in the style guide? Is there a way to disable this specific check?

On a side note, this is working fine and Kotlin Lint doesn't complain

            .assertValueAt(2) {
                it is ImageChangeEvent.ImageUpdated
                        && it.position == 0 &&
                        it.changedFields.contains(CollectImage.IMAGE_MODE)
                        && it.image.imageMode == newImageMode
            }

Most helpful comment

How can we get the intellij auto-formatter to always move those operators to the end of the line? I can't find any options for that setting 馃

All 8 comments

See https://github.com/shyiko/ktlint/issues/163#issuecomment-369418775.
Also, thank you for the snippet.

Fixed in 0.20.0.

@shyiko No, it's still not working as expected.

if (!isLocal
    && workspace.userId != account.userId
    && workspace.contactId != account.userId) {
}
Class.kt:378:25: Line must not begin with "&&"
Class.kt:379:25: Line must not begin with "&&"

Should I create a new issue or do you want to reopen this one?

@vRallev It works in accordance with https://github.com/shyiko/ktlint/issues/163#issuecomment-369418775.

I can't follow the comments in the link. They're mostly talking about +/- and not && or ||. I couldn't find anything about that. Note that the auto-formatter inside of IntelliJ formats my sample from above like this:

if (!isLocal
    && workspace.userId != account.userId
    && workspace.contactId != account.userId
) {
    // do something after 4 space indent
}

But for the formatter the following is also fine

if (!isLocal && 
    workspace.userId != account.userId && 
    workspace.contactId != account.userId
) {
    // do something after 4 space indent
}

So there's no evidence which one of them is correct.

How can we get the intellij auto-formatter to always move those operators to the end of the line? I can't find any options for that setting 馃

How can we get the intellij auto-formatter to always move those operators to the end of the line? I can't find any options for that setting 馃

Did you find a solution for that?

How can we get the intellij auto-formatter to always move those operators to the end of the line? I can't find any options for that setting thinking

Did you find a solution for that?

Have you found the settings for that?

Was this page helpful?
0 / 5 - 0 ratings