tools: Index | Files

package imports

import ""

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


Package Files

fix.go imports.go mod.go sortimports.go zstdlib.go

func Process Uses

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

Process implements with explicit context in env.

func VendorlessPath Uses

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".

type Options Uses

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 with extra internal-only options.

type ProcessEnv Uses

type ProcessEnv struct {
    LocalPrefix string
    Debug       bool

    // If non-empty, these will be used instead of the
    // process-wide values.
    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.

Package imports imports 30 packages (graph) and is imported by 3 packages. Updated 2019-07-15. Refresh now. Tools for package owners.