pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.23k stars 512 forks source link

Format can causes compile error if function has multi line comments #2355

Closed RyosukeFukatani closed 11 months ago

RyosukeFukatani commented 11 months ago

Expected Behavior

Input

fun zero():
        Float
// comment1
// comment2
{
    return 0.0f
}

Expected result

fun zero(): Float {
// comment1
// comment2
    return 0.0f
}

or other compilable code.

Observed Behavior

Unfortunately we got non-compilable code.

fun zero(): Float
// comment1 { // comment2
        return 0.0f
    }

Your Environment

paul-dingemans commented 11 months ago

Tnx fore the report. This is clearly a bug. I am not sure whether I can solve it within reasonable bounds. But least that I can do, is to disallow this particular location for a comment.

I don't know your usage of this way of commenting, but I would most likely have put the comment somewhere else.

RyosukeFukatani commented 11 months ago

Thanks! Actually, we consider this commenting style to be an unusual one and do not intend to continue using it. In general, the following styles are considered preferable.

// comment1
// comment2
fun zero(): Float {
    return 0.0f
}