Error parsing new context in kotlin 2.2.0
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 ')'
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
Upstream issue (should be resolved when ktlint 1.7.0 is released):
- https://github.com/pinterest/ktlint/issues/2953
Unblocked:
https://github.com/pinterest/ktlint/releases/tag/1.7.0
Context parameters are still not working in version 14.0.1
@jasonctoms You can get around this problem by overriding the default ktlint version wherever you configure ktlint.
@MJ-Hayden Can you please give a example about how to overriding the ktlint version?
@JLLeitschuh Any updates for this issue?
@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")
}
Am I doing something wrong? The problem is still there.