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

Trailing comment is reported as wrong indentation #710

Closed
lwasyl opened this issue Mar 5, 2020 · 4 comments · Fixed by #743
Closed

Trailing comment is reported as wrong indentation #710

lwasyl opened this issue Mar 5, 2020 · 4 comments · Fixed by #743

Comments

@lwasyl
Copy link

lwasyl commented Mar 5, 2020

Ktlint 0.36.0

For the following code:

val item = createItem()
    .copy(id = 42), // Reuse ID from previous item

KtLint complains with [experimental:indent] Missing newline after "," and reformats this code to

val item = createItem()
    .copy(id = 42), 
    // Reuse ID from previous item

This is not right, sice it's a comment and it pertains to that specific line. It also fits within the column limit.

@romtsn
Copy link
Collaborator

romtsn commented May 13, 2020

@lwasyl hm, could you post the full example? I don't think it's a valid Kotlin code, or is it new trailing comma?

@lwasyl
Copy link
Author

lwasyl commented May 13, 2020

Yeah, sorry, I must've copied it wrong. Overall this issue happened when I had a comment in the same line as a parameter, and there were more parameters below. It's not related to the new trailing comma feature

@romtsn
Copy link
Collaborator

romtsn commented May 14, 2020

Weird, I've tried to reproduce it, but this is passing just fine, I guess you had something more sophisticated :)

fun test() {
    run(
        1, // blah
        "2",
        "3"
    )
}

fun run(stuff: Int, stuff1: String, stuff2: String) = Unit

@lwasyl
Copy link
Author

lwasyl commented May 14, 2020

That's right, I checked and here's the offending code:

fun foo(param: Foo, other: String) {
    foo(
        param = param
            .copy(foo = ""), // A comment
        other = ""
    )
}

data class Foo(val foo: String, val bar: Int)

Fails on line with .copy

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