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

Line must not begin with "&&" rule not working in when conditions #1130

Closed
henningBunk opened this issue Apr 1, 2021 · 0 comments · Fixed by #1181
Closed

Line must not begin with "&&" rule not working in when conditions #1130

henningBunk opened this issue Apr 1, 2021 · 0 comments · Fixed by #1181
Labels

Comments

@henningBunk
Copy link

henningBunk commented Apr 1, 2021

Expected Behavior

A line which starts with && triggers a rule violation.

Observed Behavior

Given the code:

fun exampleA() {
    return when {
        locationName != null &&
            latitude != null
            && longitude != null -> {
            Unit
        }
        else -> null
    }
}

fun exampleB() {
    val a = locationName != null &&
        latitude != null
        && longitude != null

    return when {
        a -> {
            Unit
        }
        else -> null
    }
}

The Line must not begin with "&&" rule will only be triggered for exampleB, not for exampleA.

Steps to Reproduce

Your Environment

  • Version of ktlint used: 0.39
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): gradle, leitschuh plugin
  • Version of Gradle used (if applicable): 6.8
  • Operating System and version: MacOS
  • Link to your project (if it's a public repository): n/a
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants