goimports

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2020 License: MIT Imports: 8 Imported by: 0

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

View Source
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 WithEnv

func WithEnv(env map[string]string) Option

WithEnv sets the spell incantation specific environment.

func WithExtraArgs

func WithExtraArgs(extraArgs ...string) Option

WithExtraArgs sets additional arguments to pass to the "goimports" module command.

func WithListNonCompliantFiles

func WithListNonCompliantFiles(listNonCompliantFiles bool) Option

WithListNonCompliantFiles indicates whether files, whose formatting are not conform to the style guide, are listed.

func WithLocalPkgs

func WithLocalPkgs(localPkgs ...string) Option

WithLocalPkgs sets local packages whose imports will be placed after 3rd-party packages.

func WithModulePath

func WithModulePath(path string) Option

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

func WithPaths(paths ...string) Option

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

func WithPersistedChanges(persistChanges bool) Option

WithPersistedChanges indicates whether results are written to the source files instead of standard output.

func WithReportAllErrors

func WithReportAllErrors(reportAllErrors bool) Option

WithReportAllErrors indicates whether all errors should be printed instead of only the first 10 on different lines.

func WithVerboseOutput

func WithVerboseOutput(verbose bool) Option

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

func NewOptions(opts ...Option) (*Options, error)

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

func New(wand wand.Wand, ac app.Config, opts ...Option) (*Spell, error)

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) Env

func (s *Spell) Env() map[string]string

Env returns spell incantation specific environment variables.

func (*Spell) Formula

func (s *Spell) Formula() []string

Formula returns the spell incantation formula.

func (*Spell) GoModuleID

func (s *Spell) GoModuleID() *project.GoModuleID

GoModuleID returns partial Go module identifier information.

func (*Spell) Kind

func (s *Spell) Kind() spell.Kind

Kind returns the spell incantation kind.

func (*Spell) Options

func (s *Spell) Options() interface{}

Options returns the spell incantation options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL