Find collection null-safety idioms

Proprietary

listOf(...).filterNotNull() vs listOfNotNull(...), map { }.filterNotNull() vs mapNotNull { }, filter { it != null }.map { it!! } chains, firstOrNull patterns where single is intended, ?.x.orEmpty() mixed-call shapes.

org.openrewrite.kotlin.idiom.FindCollectionNullSafety$KtRecipe
mod run . --recipe='org.openrewrite.kotlin.idiom.FindCollectionNullSafety$KtRecipe'

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.

Recipe list

It runs these recipes, in this order.

  1. Find listOf(a, b, c).filterNotNull() patterns
  2. Find setOf(a, b, c).filterNotNull() patterns
  3. Find map { ... }.filterNotNull() chains
  4. Find filter { it != null }.map { it!! } chains
  5. Find firstOrNull { } ?: error(...) patterns
  6. Find x?.firstOrNull() calls
  7. Find x?.something.orEmpty() patterns