pinterest / ktlint

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

operator get with lambda: incorrect error #2675

Closed Jolanrensen closed 1 month ago

Jolanrensen commented 1 month ago

Expected Behavior

Given:

class DB {
    operator fun <T> get(query: DB.() -> T): T = TODO()
}

val db = DB()
val query = db[{ 123 }]

so, an operator get function with a lambda argument inside, KtLint should be happy with this notation. It is accepted by IntelliJ.

Observed Behavior

We get a linting error: Lint error > [standard:curly-spacing] Missing spacing before "{".

If I run the formatter instead it performs a fix and reverts it again: Format fixed > [standard:curly-spacing] Missing spacing before "{"

Format fixed > [standard:square-brackets-spacing] Unexpected spacing after '['

Steps to Reproduce

See the example above.

Your Environment