Search code examples
kotlindetekt

Detekt VarCouldBeVal rule doesn't seem to work


I've noticed that Detekt doesn't report issues with this code

fun main() {
    var thisCouldBeVal = "this could be val"
    println(thisCouldBeVal)
}

Isn't this a clear case where VarCouldBeVal rule should be triggered, or am I missing something?

Here's a sample project to repro https://github.com/Trixmegist/detekt-test

  • Detekt v1.23.0
  • Kotlin v1.9.0

Solution

  • VarCouldBeVal rule requires type resolution to work https://detekt.dev/docs/gettingstarted/type-resolution/