Reports different ways of checking emptiness of collections and Options
and suggests replacing them with .isEmpty
,
.nonEmpty
, or .isDefined.
Example:
!Seq(1).isEmpty
Seq(1).size == 0
Seq(1).size != 0
!(Seq(1).length > 0)
Seq(1).exists(_ => true)
import scala.Function.const
Seq(1).exists(const(true))
!Option(0).isEmpty
Option(0) == None
Option(0) != None
After the quick-fix is applied:
Seq(1).nonEmpty
Seq(1).isEmpty
Seq(1).nonEmpty
Seq(1).isEmpty
Seq(1).nonEmpty
import scala.Function.const
Seq(1).nonEmpty
Option(0).isDefined
Option(0).isEmpty
Option(0).isDefined