goimports

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package goimports provides a task for the "golang.org/x/tools/cmd/goimports" Go module command. "goimports" 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 module import path.
	DefaultGoModulePath = "golang.org/x/tools/cmd/goimports"

	// TaskName is the name of the task.
	TaskName = "goimports"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Options)

Option is a task option.

func WithEnv

func WithEnv(env map[string]string) Option

WithEnv sets the task specific environment.

func WithExtraArgs

func WithExtraArgs(extraArgs ...string) Option

WithExtraArgs sets additional arguments to pass to the 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 module import path. Defaults to DefaultGoModulePath.

func WithModuleVersion

func WithModuleVersion(version *semver.Version) Option

WithModuleVersion sets the module version.

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 task options.

func NewOptions

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

NewOptions creates new task options.

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task is a task for the "golang.org/x/tools/cmd/goimports" Go module command. "goimports" 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.

func New

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

New creates a new task for the "golang.org/x/tools/cmd/goimports" Go module command.

func (*Task) BuildParams

func (t *Task) BuildParams() []string

BuildParams builds the parameters.

func (*Task) Env

func (t *Task) Env() map[string]string

Env returns the task specific environment.

func (*Task) ID

func (t *Task) ID() *project.GoModuleID

ID returns the identifier of the Go module.

func (*Task) Kind

func (t *Task) Kind() task.Kind

Kind returns the task kind.

func (*Task) Options

func (t *Task) Options() task.Options

Options returns the task options.

Jump to

Keyboard shortcuts

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