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 in an if statement fails with an indent issue #900

Closed
ZakTaccardi opened this issue Sep 10, 2020 · 2 comments · Fixed by #949
Closed

Multiline in an if statement fails with an indent issue #900

ZakTaccardi opened this issue Sep 10, 2020 · 2 comments · Fixed by #949

Comments

@ZakTaccardi
Copy link

Expected Behavior

I expect the following to pass formatting.

fun broken(key: String): Letter {
    for (letter in Letter.values()) {
        if (
            letter.value
                .equals(
                    key,
                    ignoreCase = true
                )
        ) {
            return letter
        }
    }
    return Letter.B
}

Observed Behavior

Fails with: Unexpected indentation (28) (should be 32) (indent)

Steps to Reproduce

enum class Letter(val value: String) {
    A("a"),
    B("b");
}
fun broken(key: String): Letter {
    for (letter in Letter.values()) {
        if (
            letter.value
                .equals(
                    key,
                    ignoreCase = true
                )
        ) {
            return letter
        }
    }
    return Letter.B
}
fun fixed1(key: String): Letter {
    for (letter in Letter.values()) {
        if (
            letter.value
                .equals(key, ignoreCase = true)
        ) {
            return letter
        }
    }
    return Letter.B
}
fun fixed2(key: String): Letter {
    for (letter in Letter.values()) {
        if (letter.value.equals(key, ignoreCase = true)) {
            return letter
        }
    }
    return Letter.B
}

Your Environment

  • Version of ktlint used: 0.38.1 (command line)
  • AS 4.0.1 with AGP 3.6
  • Operating System and version: MacOS 10.15.6
@ZakTaccardi
Copy link
Author

ZakTaccardi commented Sep 10, 2020

This could likely be the same issue and have the same resolution as #898 (but unable to test 39.0 yet)

@Tapchicoma
Copy link
Collaborator

yes, it fails on current master

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