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

")" unexpectedly indented in expression but not in if #920

Closed
mathjeff opened this issue Sep 21, 2020 · 4 comments · Fixed by #2127
Closed

")" unexpectedly indented in expression but not in if #920

mathjeff opened this issue Sep 21, 2020 · 4 comments · Fixed by #2127
Labels
bug conflict-with-default-intellij-formatting Code produced by KtLint is not accepted by the IntelliJ default formatter indentation rule ktlint-official-codestyle
Milestone

Comments

@mathjeff
Copy link

mathjeff commented Sep 21, 2020

Given ktlint 0.39.0 and some code that looks like this:

val pass = if (condition1) {                 
        (
            condition2
        )
    } else {
        condition3
    }

Expected Behavior:

this code seems to be formatted reasonably to us; we think ktlint should report no problems.

Observed Behavior:

Instead we're observing it to request indenting "condition2" and ")" to get this:

val pass = if (condition1) {                 
        (
                condition2
            )
    } else {
        condition3
    }

At first I thought this seemed reasonable to me because it was presumably being treated as a line continuation, but then I checked what would happen if condition1 were multiple lines, and found in that case that ktlint requested that the parentheses of the if statement should be lined up:

if (
    condition1
) { // indendation matching the corresponding "("
    (
            condition2
        ) // indentation not matching the corresponding "("
} else {
    condition3
}

Your Environment

We encounter this when upgrading from ktlint 0.36.0 to 0.39.0

The full code in question: https://android-review.googlesource.com/c/platform/frameworks/support/+/1432017/2/compose/animation/animation-core/src/test/java/androidx/compose/animation/core/SpringEstimationTest.kt#139

@romtsn
Copy link
Collaborator

romtsn commented Sep 26, 2020

That is a known quirk of the Kotlin ide plugin formatter (whose behavior we are trying to match), please check #810 for details. I've also filed an issue on youtrack and have to close this until further notice from JB, as it seems to be expected behavior.

@romtsn romtsn closed this as completed Sep 26, 2020
@oakkitten
Copy link

I gave that YouTrack issue a thumbs up, which brought the total number of thumbs up to two. It's been two years, perhaps it's worth considering whether it could be okay to allow deviating from the IDE formatter in cases such as this? This looks super weird 🤪

@paul-dingemans paul-dingemans added the conflict-with-default-intellij-formatting Code produced by KtLint is not accepted by the IntelliJ default formatter label Oct 30, 2022
@mklnwt
Copy link

mklnwt commented Mar 28, 2023

I also gave it a thumbs up. Any chance we could at least add a flag to allow deviation?

@paul-dingemans
Copy link
Collaborator

Reopened issue for investigation. If it gets solved, it will only be solved for the new code style ktlint_official.

@paul-dingemans paul-dingemans added this to the 1.0 (Yeah!) milestone Apr 16, 2023
paul-dingemans added a commit that referenced this issue Jul 13, 2023
paul-dingemans added a commit that referenced this issue Jul 15, 2023
paul-dingemans added a commit that referenced this issue Jul 15, 2023
* In code style `ktlint_official` do not indent the closing parenthesis of a PARENTHESIZED expression

Closes #920
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug conflict-with-default-intellij-formatting Code produced by KtLint is not accepted by the IntelliJ default formatter indentation rule ktlint-official-codestyle
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants