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

indentation rule inserts unnecessary spacings inside multiline if-else condition #871

Closed
romtsn opened this issue Aug 28, 2020 · 3 comments · Fixed by #949
Closed

indentation rule inserts unnecessary spacings inside multiline if-else condition #871

romtsn opened this issue Aug 28, 2020 · 3 comments · Fixed by #949

Comments

@romtsn
Copy link
Collaborator

romtsn commented Aug 28, 2020

Expected Behavior

Expect this code to remain unchanged after reformatting

fun function(): Boolean {
    return if (
        listOf(
            param1,
            param2,
            param3
        ).none { it != null }
    ) {
        true
    } else {
        false
    }
}

Observed Behavior

fun function(): Boolean {
    return if (
        listOf(
                param1,
                param2,
                param3
            ).none { it != null }
    ) {
        true
    } else {
        false
    }
}

Steps to Reproduce

Try to format the given example, indentation rule will insert unnecessary spacings before arguments and rbrace

Your Environment

  • Version of ktlint used: 0.38.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): CLI
@fishy
Copy link

fishy commented Sep 5, 2020

I'm seeing a similar issue on 0.38.1.

I have the code of:

        if (
            pref.getBoolean(
                SettingsActivity.KEY_BIO_AUTOLOAD,
                SettingsActivity.DEFAULT_BIO_AUTOLOAD
            )
        ) {

ktlint would complain about Unexpected indentation (16) (should be 20) on the two args lines and closing parenthesis line. ktlint -F would try to reformat it as:

        if (
            pref.getBoolean(
                    SettingsActivity.KEY_BIO_AUTOLOAD,
                    SettingsActivity.DEFAULT_BIO_AUTOLOAD
                )
        ) {

And still complain about those 3 lines.

@aljidy
Copy link

aljidy commented Sep 7, 2020

I get the same issue here on 0.38.1 with this:

  onNextAction?.let {
                setOnEditorActionListener { _, actionId, _ ->
                    if (actionId in arrayOf(
                            IME_ACTION_NEXT,
                            IME_ACTION_DONE
                        )
                    ) {
                        it.invoke()
                        true
                    } else {
                        false
                    }
                }
            }

it alternates between these two sets of warnings depending on the indents:

file.kt:85:29: Unexpected indentation (expected 24, actual 28)
file.kt:86:29: Unexpected indentation (expected 24, actual 28)
file.kt:87:25: Unexpected indentation (expected 20, actual 24)
file.kt:85:1: Unexpected indentation (24) (should be 28)
file.kt:86:1: Unexpected indentation (24) (should be 28)
file.ktt:87:1: Unexpected indentation (20) (should be 24)

@grrowit
Copy link

grrowit commented Oct 7, 2020

I can confirm it is happening still with latest version

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