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

Opening bracket for if-else is added to a commented line (output won't compile) #944

Closed
ming-zhang opened this issue Oct 15, 2020 · 0 comments · Fixed by #945
Closed

Opening bracket for if-else is added to a commented line (output won't compile) #944

ming-zhang opened this issue Oct 15, 2020 · 0 comments · Fixed by #945

Comments

@ming-zhang
Copy link

ming-zhang commented Oct 15, 2020

Source Code

val x = 5
val output = if (x > 0) 
// Greater than zero
    "Positive"
else
// Not greater than zero
    "Not positive"

Expected Behavior

ktlint --experimental --format should yield:

val x = 5
val output = if (x > 0) {
    // Greater than zero
    "Positive"
} else {
    // Not greater than zero
    "Not positive"
}

Observed Behavior

Generates code that doesn't compile:

val x = 5
val output = if (x > 0)
// Greater than zero {
    "Positive"
} else
// Not greater than zero {
    "Not positive"
}

Your Environment

  • Version of ktlint used: 0.39.0
@ming-zhang ming-zhang changed the title Opening bracket for if-else is added to a commented line Opening bracket for if-else is added to a commented line (output won't compile) Oct 15, 2020
# 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.

1 participant