Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

MultilineIfElseRule inserts unnecessary empty lines #793

Closed
romtsn opened this issue Jun 22, 2020 · 0 comments · Fixed by #797
Closed

MultilineIfElseRule inserts unnecessary empty lines #793

romtsn opened this issue Jun 22, 2020 · 0 comments · Fixed by #797
Labels
Milestone

Comments

@romtsn
Copy link
Collaborator

romtsn commented Jun 22, 2020

This is most likely a regression from #727

Expected Behavior

I expect this code snippet

val listenerDisposableHandle = coroutineContext[Job]!!.invokeOnCompletion(onCancelling = true) { cancelCause ->
    val parentJob = ref.state

    if (cancelCause is CancellationException)
        parentJob.cancel(cause = cancelCause)
    else
        parentJob.cancel()
}

to be reformatted to

val listenerDisposableHandle = coroutineContext[Job]!!.invokeOnCompletion(onCancelling = true) { cancelCause ->
    val parentJob = ref.state

    if (cancelCause is CancellationException) {
        parentJob.cancel(cause = cancelCause)
    } else {
        parentJob.cancel()
    }
}

Observed Behavior

However, this gets reformatted to

val listenerDisposableHandle = coroutineContext[Job]!!.invokeOnCompletion(onCancelling = true) { cancelCause ->
    val parentJob = ref.state

    if (cancelCause is CancellationException) {
        parentJob.cancel(cause = cancelCause)

    } else {
        parentJob.cancel()

    }
}

with unnecessary empty lines before rbraces

Steps to Reproduce

Run ktlint --format on the snippet from the expected behavior
The issue was discovered in this pull request touchlab/KaMPKit#115

Your Environment

  • Version of ktlint used: 0.37.2
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): ktlint-gradle plugin 9.2.1
  • Version of Gradle used (if applicable): 5.6.4
  • Operating System and version: MacOS Catalina version 10.15.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants