Remove unused local variables

MSAL

If a local variable is declared but not used, it is dead code and should be removed. Unused variables increase cognitive load for readers who must determine whether the variable matters, and they may signal incomplete implementations or missed refactoring.

org.openrewrite.staticanalysis.RemoveUnusedLocalVariables

Optional

An array of variable identifier names for local variables to ignore, even if the local variable is unused. Separate values with commas.

A fully qualified class name. Only unused local variables whose type matches this will be removed. If empty or not set, all unused local variables are considered for removal.

withSideEffectsBoolean

Whether to remove unused local variables despite side effects in the initializer. Default false.

mod run . --recipe=org.openrewrite.staticanalysis.RemoveUnusedLocalVariables

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