Skip to content

Repository tools imports formatter README

alanxtl edited this page Sep 20, 2026 · 1 revision

imports-formatter

主仓库文档快照;main 的说明不自动适用于所有已发布版本。 来源:原文 · 提交 832124aaacf0 · 返回目录

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.

Clone this wiki locally