KT.USE_IF_INSTEAD_OF_WHEN

Use 'if' instead of 'when'

Binary expressions are better expressed using an if expression than a when expression. See https://kotlinlang.org/docs/coding-conventions.html#if-versus-when

Noncompliant Code

Copy
when (x) {
    null -> true
    else -> false
}

Compliant Code

Copy
if (x == null) true else false

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html