ktlint-gradle icon indicating copy to clipboard operation
ktlint-gradle copied to clipboard

Error parsing new context in kotlin 2.2.0

Open alekseytomin opened this issue 10 months ago • 9 comments

Project example: https://github.com/alekseytomin/ktlint-context

code:

fun main() {
    with("test") {
        print()
    }
}

context(x: String)
fun print() {
    println(x)
}

Check:

 >./gradlew ktlintCheck                                               

> Task :runKtlintCheckOverMainSourceSet FAILED
7:10 Expecting comma or ')'

alekseytomin avatar Jul 02 '25 07:07 alekseytomin

If I were to guess, this is because the underlying version of ktlint doesn't support this API yet. This is a bug in the upstream ktlint version, not this plugin

JLLeitschuh avatar Jul 03 '25 19:07 JLLeitschuh

Upstream issue (should be resolved when ktlint 1.7.0 is released):

  • https://github.com/pinterest/ktlint/issues/2953

david-allison avatar Jul 07 '25 18:07 david-allison

Unblocked:

https://github.com/pinterest/ktlint/releases/tag/1.7.0

david-allison avatar Jul 14 '25 21:07 david-allison

Context parameters are still not working in version 14.0.1

jasonctoms avatar Nov 19 '25 08:11 jasonctoms

@jasonctoms You can get around this problem by overriding the default ktlint version wherever you configure ktlint.

MJ-Hayden avatar Nov 20 '25 21:11 MJ-Hayden

@MJ-Hayden Can you please give a example about how to overriding the ktlint version?

LyyySong avatar Nov 21 '25 06:11 LyyySong

@JLLeitschuh Any updates for this issue?

LyyySong avatar Nov 21 '25 06:11 LyyySong

@LyyySong The KtlintExtension contains a version property that allows you set the upstream ktlint version. In your project build file, or wherever you've got your ktlint config happening, it'd look like this

ktlint {
    version.set("1.8.0")
}

MJ-Hayden avatar Nov 21 '25 16:11 MJ-Hayden

Image Image

Am I doing something wrong? The problem is still there.

Spinoza0 avatar Dec 04 '25 08:12 Spinoza0