← All recipes
Moderne licensed

Remove import

Recipe IDorg.openrewrite.golang.RemoveImportArtifactgithub.com/moderneinc/recipes-go

Remove an import statement from a Go compilation unit. Matches by import path, in any form (regular, aliased, dot, blank). Unless force is set, an import that the file still references is kept, as are blank (_) and dot (.) imports.

Single recipeProprietary

Usage

You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.golang.RemoveImport --recipe-option "packagePath=fmt"

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

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

Options

NameTypeDescription
packagePathrequiredStringThe import path to remove.
e.g. fmt
forceBooleanWhen true, remove the import even if the file still references the package, and remove blank (_) and dot (.) imports.