← All recipes
Moderne licensed

Open file outside loop

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

Find os.Open() or os.Create() calls inside for/range loops. Opening files in tight loops should use a single open outside the loop.

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.OpenFileOutsideLoop

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

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