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