Find nullability idiom opportunities

Proprietary

Search-only bundle for nullable-handling if/else shapes that map to Kotlin idioms: if (x != null) x else default (use ?:), if (x != null) f(x) else null (use x?.let { f(it) }), if (x == null) throw IllegalArgumentException (use requireNotNull), if (x == null) throw IllegalStateException (use checkNotNull), and if (p(x)) x else null (use x.takeIf { p(it) }).

org.openrewrite.kotlin.functional.FindNullabilityErgonomics$KtRecipe
mod run . --recipe='org.openrewrite.kotlin.functional.FindNullabilityErgonomics$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 if (x != null) x else default patterns
  2. Find if (x != null) f(x) else null patterns
  3. Find if (x == null) throw IllegalArgumentException(...) patterns
  4. Find if (x == null) throw IllegalStateException(...) patterns
  5. Find if (predicate(x)) x else null patterns