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

False positive at multiline-if-else when using "else if" #1904

Closed
carstenhag opened this issue Mar 31, 2023 · 2 comments · Fixed by #1923
Closed

False positive at multiline-if-else when using "else if" #1904

carstenhag opened this issue Mar 31, 2023 · 2 comments · Fixed by #1923
Milestone

Comments

@carstenhag
Copy link

Expected Behavior

else if () {
}

Should stay as is

Observed Behavior

It gets formatted to

else {
   if () {
   }
}

Steps to Reproduce

    val x = if (showFilter) {
        1
    } else if (activeTabIndex.value == 0) {
        2
    } else {
        null
    } ?: 0

-->

    val x = if (showFilter) {
        1
    } else {
        if (activeTabIndex.value == 0) {
            2
        } else {
            null
        } ?: 0
    }

Your Environment

  • Version of ktlint used: 0.48.2
  • Relevant parts of the .editorconfig settings
  • Operating System and version: macOS
@paul-dingemans
Copy link
Collaborator

Tnx for reporting. It is just in time to be fixed in next release.

@paul-dingemans paul-dingemans added this to the 0.49.0 milestone Mar 31, 2023
@paul-dingemans
Copy link
Collaborator

Similarly the example below should be accepted without reformatting as well:

val foo = if (bar1) {
    "bar1"
} else if (bar2) {
    "bar2"
} else {
    "bar3"
}.plus("foo")

# 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