Scala

Scala

Made by DeepSource

Consider using .isEmpty or .nonEmpty when checking for empty Strings SC-R1022

Anti-pattern
Minor

The String type in Scala implements methods such as .isEmpty and .nonEmpty that you can use to check if a string is empty or not. While you can also use the comparison operators against an empty string, it is generally not considered as the right approach and is recommended that you use the said builtin methods.

Bad Practice

val lang = " Scala "
if (lang != "" && lang.trim != "") {
  // ...
}

Recommended

val lang = " Scala "
if (lang.nonEmpty && lang.trim.nonEmpty) {
  // ...
}