I am migrating my project o kotlin 2.2.0 and getti...
# detekt
j
I am migrating my project o kotlin 2.2.0 and getting lots of false positive... for instance UnusedPrivateMember for
Copy code
private fun FSProductToAdd.toOrderPipeModel(): OPProductToAdd {
    return OPProductToAdd(
        productId = productId,
        quantity = quantity
    )
}
even thought that is called inside of the class... I also got a bunch of RedundantSuspendModifier
Copy code
private suspend fun register() = suspendCoroutine { cont ->
// do integration with callbacks from tracking library
}
also UnreachableCode
Copy code
internal fun decodeJwt(token: String): JSONObject? {
    var stringToDecode = (token.split('.').getOrNull(1) ?: return null)
        .replace('-', '+')
        .replace('_', '/')

    @Suppress("MagicNumber")
    when (stringToDecode.codePointCount(0, stringToDecode.lastIndex) % 4) {
        2 -> stringToDecode += "=="
        3 -> stringToDecode += '='
        else -> {
            // nothing to do
        }
    }

--> line 32    return try {
        stringToDecode.decodeBase64()?.utf8()?.let(::JSONObject)
    } catch (e: JSONException) {
        Timber.e(e, "Tried to decode a JSON Web Token that is not JSON!")
        null
    }
}
saying
JwtDecoder.kt:32:5: This expression is unreachable code which should either be used or removed. [UnreachableCode]
1
b
Yes, Kotlin 2.2 and the last stable version of detekt doesn't work too good together. You can use the snapshots or wait for detekt 2.0 alpha that should be realised soon. But it will be alpha, we expect more breaking changes before a stable version.
👍 1
d
Will there be a backport for Kotlin 2.2 for 1.23.x?
Hrm... just read up on it, most likely not because the language level is not supported for a long time now (I guess for a reason) https://github.com/detekt/detekt/issues/7304
Maybe it would be a good idea to prominently warn people on the GH page to not use Detekt 1.23.x with Kotlin 2.2 or alternatively provide the first alphas of 2.0.