KT.USE_IS_NULL_OR_EMPTY

Null or empty check can be replaced with 'isNullOrEmpty()' call

This rule detects null or empty checks that can be replaced with isNullOrEmpty() call.

Noncompliant Code

Copy
fun foo(x: List<Int>?) {
    if (x == null || x.isEmpty()) return
}
fun bar(x: List<Int>?) {
    if (x == null || x.count() == 0) return
}
fun baz(x: List<Int>?) {
    if (x == null || x.size == 0) return
}

Compliant Code

Copy
if (x.isNullOrEmpty()) return

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