imports

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2019 License: BSD-3-Clause, BSD-3-Clause Imports: 30 Imported by: 0

Documentation

Overview

Package imports implements a Go pretty-printer (like package "go/format") that also adds or removes import statements as necessary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Process

func Process(filename string, src []byte, opt *Options) ([]byte, error)

Process implements golang.org/x/tools/imports.Process with explicit context in env.

func VendorlessPath

func VendorlessPath(ipath string) string

VendorlessPath returns the devendorized version of the import path ipath. For example, VendorlessPath("foo/bar/vendor/a/b") returns "a/b".

Types

type ModuleErrorJSON added in v0.0.22

type ModuleErrorJSON struct {
	Err string // the error itself
}

type ModuleJSON added in v0.0.22

type ModuleJSON struct {
	Path     string           // module path
	Version  string           // module version
	Versions []string         // available module versions (with -versions)
	Replace  *ModuleJSON      // replaced by this module
	Time     *time.Time       // time version was created
	Update   *ModuleJSON      // available update, if any (with -u)
	Main     bool             // is this the main module?
	Indirect bool             // is this module only an indirect dependency of main module?
	Dir      string           // directory holding files for this module, if any
	GoMod    string           // path to go.mod file for this module, if any
	Error    *ModuleErrorJSON // error loading module
}

type ModuleResolver added in v0.0.22

type ModuleResolver struct {
	Initialized   bool
	Main          *ModuleJSON
	ModsByModPath []*ModuleJSON // All modules, ordered by # of path components in module Path...
	ModsByDir     []*ModuleJSON // ...or Dir.
	// contains filtered or unexported fields
}

ModuleResolver implements resolver for modules using the go command as little as feasible.

type Options

type Options struct {
	Env *ProcessEnv // The environment to use. Note: this contains the cached module and filesystem state.

	Fragment  bool // Accept fragment of a source file (no package statement)
	AllErrors bool // Report all errors (not just the first 10 on different lines)

	Comments  bool // Print comments (true if nil *Options provided)
	TabIndent bool // Use tabs for indent (true if nil *Options provided)
	TabWidth  int  // Tab width (8 if nil *Options provided)

	FormatOnly bool // Disable the insertion and deletion of imports
}

Options is golang.org/x/tools/imports.Options with extra internal-only options.

type ProcessEnv

type ProcessEnv struct {
	LocalPrefix string
	Debug       bool

	// If non-empty, these will be used instead of the
	// process-wide values.
	GOPATH, GOROOT, GO111MODULE, GOPROXY, GOFLAGS, GOSUMDB string
	WorkingDir                                             string

	// If true, use go/packages regardless of the environment.
	ForceGoPackages bool

	// Logf is the default logger for the ProcessEnv.
	Logf func(format string, args ...interface{})
	// contains filtered or unexported fields
}

ProcessEnv contains environment variables and settings that affect the use of the go command, the go/build package, etc.

func (*ProcessEnv) GetResolver added in v0.0.22

func (e *ProcessEnv) GetResolver() Resolver

type Resolver added in v0.0.22

type Resolver interface {
	// contains filtered or unexported methods
}

A Resolver does the build-system-specific parts of goimports.

Jump to

Keyboard shortcuts

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