← All recipes
Moderne licensed

Simplify redundant len check before range

Recipe IDorg.openrewrite.golang.codequality.SimplifyRedundantLenBeforeRangeArtifactgithub.com/moderneinc/recipes-go

Remove if len(s) > 0 { for ... range s } where the len check is redundant because range over nil/empty produces zero iterations.

Single recipeProprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.golang.codequality.SimplifyRedundantLenBeforeRange

If the recipe isn’t available locally, install it with:

mod config recipes go install github.com/moderneinc/recipes-go