English | 中文
imports-formatter rewrites Go import blocks using the grouping style used by dubbo-go.
It scans a Go module, skips generated files that contain Code generated by, and groups imports into:
- Go standard library imports
- third-party imports
- current module imports
go install dubbo.apache.org/dubbo-go/v3/tools/imports-formatter@latestMake sure $(go env GOPATH)/bin is in your PATH.
You can also install it through dubbogo-cli:
dubbogo-cli install formatterFormat the current module:
imports-formatterFormat a specific module path:
imports-formatter --path /path/to/modulePass the module path explicitly when the target directory does not contain go.mod:
imports-formatter --path /path/to/module/subdir --module dubbo.apache.org/dubbo-go/v3Disable blank lines between third-party import groups:
imports-formatter --bl=false| Flag | Default | Description |
|---|---|---|
--path |
current directory | Directory to scan recursively. |
--module |
module from go.mod |
Go module path used to identify internal imports. |
--bl |
true |
Whether to insert blank lines between third-party import groups. |
imports-formatter edits files in place. Review the diff before committing.