Skip to content

Go formatter that formats Go files and organizes imports into sections

License

Notifications You must be signed in to change notification settings

palantir/go-ptimports

Repository files navigation

Autorelease

go-ptimports

go-ptimports is a formatter for Go code. Functionally, it is almost identical to goimports. However, it provides the following extra functionality:

  • When the -s flag is specified, code is simplified in the same manner as gofmt -s

For example, a range statement such as:

range i, _ := arr {
    _ = i
}

becomes:

range i := arr {
    _ = i
}
  • When the -r flag is specified, any non-CGo non-block imports are converted to block imports

For example:

import "go/ast"

becomes:

import (
	"go/ast"
)

Import statements of the form import "C" (and any comments associated with such import statements) are preserved.

The output of go-ptimports is compliant with goimports and gofmt.

Runing go-ptimports without any extra flags matches the behavior of goimports. Running go-ptimports with the --format-only flag is roughly equivalent to the behavior of gofmt.