Skip to content

Files

Latest commit

 

History

History
31 lines (22 loc) · 578 Bytes

UseIsNullOrEmpty.md

File metadata and controls

31 lines (22 loc) · 578 Bytes

Pattern: Missing use of isNullOrEmpty()

Issue: -

Description

Detects null or empty checks that can be replaced with isNullOrEmpty() call.

Example of incorrect code:

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
}

Example of correct code:

if (x.isNullOrEmpty()) return

Further Reading