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
- 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 Task
Constants ¶
const ( // DefaultGoModulePath is the default module import path. DefaultGoModulePath = "golang.org/x/tools/cmd/goimports" // DefaultGoModuleVersion is the default Go module version of the runner command. DefaultGoModuleVersion = "v0.1.7" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Options)
Option is a task option.
func WithExtraArgs ¶
WithExtraArgs sets additional arguments to pass to the 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 module import path. Defaults to DefaultGoModulePath.
func WithModuleVersion ¶
func WithModuleVersion(version *semver.Version) Option
WithModuleVersion sets the module version.
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 task options.
func NewOptions ¶
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 (*Task) ID ¶
func (t *Task) ID() *project.GoModuleID
ID returns the identifier of the Go module.