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

Multiline if-else does not format else if #2420

Closed
pdb-stripe opened this issue Dec 9, 2023 · 0 comments · Fixed by #2430
Closed

Multiline if-else does not format else if #2420

pdb-stripe opened this issue Dec 9, 2023 · 0 comments · Fixed by #2430
Milestone

Comments

@pdb-stripe
Copy link

I observed yesterday that when enabling the multiline-if-else rule and running the formatter, else-if blocks were not converted to multiline.

Expected Behavior

Given this code:

if (foo) doFoo()
else if (bar) doBar()

the formatter for the multiline-if-else rule should convert it to:

if (foo) {
    doFoo()
} else if (bar) {
    doBar()
}

Observed Behavior

This code actually formats to:

if (foo) {
    doFoo()
} else if (bar) doBar()

Steps to Reproduce

We had code with this syntax:

if (foo) return doFoo()
else if (bar) return doBar()
return null

Since it probably should have used a lifted return statement or a when statement (or both), my guess is this unique scenario would not be discovered if some other rules were not also disabled - but not entirely sure.

Your Environment

Ktlint 0.50.0, MacOS

This was executed using ktlint-gradle (via ./gradlew ktlintFormat) 11.6.1 on Gradle 8.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants