Skip to content

Latest commit

 

History

History
63 lines (41 loc) · 1.37 KB

File metadata and controls

63 lines (41 loc) · 1.37 KB

imports-formatter

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

Installation

go install dubbo.apache.org/dubbo-go/v3/tools/imports-formatter@latest

Make sure $(go env GOPATH)/bin is in your PATH.

You can also install it through dubbogo-cli:

dubbogo-cli install formatter

Usage

Format the current module:

imports-formatter

Format a specific module path:

imports-formatter --path /path/to/module

Pass 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/v3

Disable blank lines between third-party import groups:

imports-formatter --bl=false

Flags

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.

Notes

imports-formatter edits files in place. Review the diff before committing.