← 返回命令列表

Linux command

gofumpt 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Format a Go file and print result to stdout

gofumpt [file.go]

Format a file in place

gofumpt -w [file.go]

Format all Go files in the current directory recursively

gofumpt -w .

Show a diff of formatting changes without applying

gofumpt -d [file.go]

Format with extra opinionated rules

gofumpt -extra [file.go]

Read from stdin and format

cat [file.go] | gofumpt

说明

gofumpt is a stricter alternative to gofmt that applies additional formatting rules beyond the standard Go style. It removes unnecessary blank lines, enforces consistent grouping, and applies other style preferences while remaining a superset of gofmt. The -extra flag enables even more opinionated rules for tighter code formatting.

参数

-w
Write result to the source file instead of stdout.
-d
Display diffs instead of rewriting files.
-e
Report all errors (not just the first 10 per file).
-extra
Enable extra formatting rules (e.g., enforce short case bodies on one line).
-l
List files whose formatting differs from gofumpt's.
-version
Print the version and exit.

FAQ

What is the gofumpt command used for?

gofumpt is a stricter alternative to gofmt that applies additional formatting rules beyond the standard Go style. It removes unnecessary blank lines, enforces consistent grouping, and applies other style preferences while remaining a superset of gofmt. The -extra flag enables even more opinionated rules for tighter code formatting.

How do I run a basic gofumpt example?

Run `gofumpt [file.go]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -w do in gofumpt?

Write result to the source file instead of stdout.