Documentation
¶
Overview ¶
Package goimports provides a spell incantation for the "golang.org/x/tools/cmd/goimports" Go module command that allows to update Go import lines, add missing ones and remove unreferenced ones. It also formats code in the same style as "https://pkg.go.dev/cmd/gofmt" so it can be used as a replacement.
See https://pkg.go.dev/golang.org/x/tools/cmd/goimports for more details about "goimports". The source code of "goimports" is available at https://github.com/golang/tools/tree/master/cmd/goimports.
Index ¶
- Constants
- type Option
- func WithEnv(env map[string]string) Option
- func WithExtraArgs(extraArgs ...string) Option
- func WithListNonCompliantFiles(listNonCompliantFiles bool) Option
- func WithLocalPkgs(localPkgs ...string) Option
- func WithModulePath(path string) Option
- func WithModuleVersion(version *semver.Version) Option
- func WithPaths(paths ...string) Option
- func WithPersistedChanges(persistChanges bool) Option
- func WithReportAllErrors(reportAllErrors bool) Option
- func WithVerboseOutput(verbose bool) Option
- type Options
- type Spell
Constants ¶
const ( // DefaultGoModulePath is the default "goimports" module command import path. DefaultGoModulePath = "golang.org/x/tools/cmd/goimports" // DefaultGoModuleVersion is the default "goimports" module version. DefaultGoModuleVersion = "latest" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Options)
Option is a spell incantation option for the "golang.org/x/tools/cmd/goimports" Go module command.
func WithExtraArgs ¶
WithExtraArgs sets additional arguments to pass to the "goimports" module command.
func WithListNonCompliantFiles ¶
WithListNonCompliantFiles indicates whether files, whose formatting are not conform to the style guide, are listed.
func WithLocalPkgs ¶
WithLocalPkgs sets local packages whose imports will be placed after 3rd-party packages.
func WithModulePath ¶
WithModulePath sets the "goimports" module import path. Defaults to DefaultGoModulePath.
func WithModuleVersion ¶
func WithModuleVersion(version *semver.Version) Option
WithModuleVersion sets the "goimports" module version. Defaults to DefaultGoModuleVersion.
func WithPaths ¶
WithPaths sets the paths to search for Go source files. By default all directories are scanned recursively starting from the current working directory.
func WithPersistedChanges ¶
WithPersistedChanges indicates whether results are written to the source files instead of standard output.
func WithReportAllErrors ¶
WithReportAllErrors indicates whether all errors should be printed instead of only the first 10 on different lines.
func WithVerboseOutput ¶
WithVerboseOutput indicates whether the output should be verbose.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options are spell incantation options for the "golang.org/x/tools/cmd/goimports" Go module command.
func NewOptions ¶
NewOptions creates new spell incantation options for the "golang.org/x/tools/cmd/goimports" Go module command.
type Spell ¶
type Spell struct {
// contains filtered or unexported fields
}
Spell is a spell incantation for the "golang.org/x/tools/cmd/goimports" Go module command.
func New ¶
New creates a new spell incantation for the "golang.org/x/tools/cmd/goimports" Go module command that allows to update Go import lines, add missing ones and remove unreferenced ones. It also formats code in the same style as "https://pkg.go.dev/cmd/gofmt" so it can be used as a replacement.
func (*Spell) GoModuleID ¶
func (s *Spell) GoModuleID() *project.GoModuleID
GoModuleID returns partial Go module identifier information.