Find manual null-check idioms

Proprietary

if (x != null) x.foo() / if (x == null) return … / if (x == null) throw … patterns where Kotlin's ?., ?: return, and ?: throw operators express the same intent in expression position.

org.openrewrite.kotlin.idiom.FindNullCheckIdioms$KtRecipe
mod run . --recipe='org.openrewrite.kotlin.idiom.FindNullCheckIdioms$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.foo() that could use ?.
  2. Find if (x != null) y = x.foo() patterns
  3. Find if (x == null) return ... early-exit patterns
  4. Find if (x == null) throw ... patterns
  5. Find if (cond) value else null patterns