gofmt
go.dev
What it is
gofmt is the Go source formatter distributed with Go installations, available on Linux, macOS, and Windows. It formats Go programs using tabs for indentation and spaces for alignment. With no path, it reads standard input; given a directory, it processes .go files recursively while skipping files whose names begin with a period. By default, reformatted source is written to standard output. Flags can show differences, list files that need formatting, apply rewrite rules, simplify code, or report all errors. The rewrite option uses patterns and replacements written as valid Go expressions. gofmt can also arrange documentation comments into canonical paragraphs, lists, headings, links, and code blocks. The Go project documents integrations for Vim, Emacs, Eclipse, and Sublime Text, plus Git pre-commit hooks and Mercurial. Since Go 1.18, it reads and formats files concurrently, with memory use limited in proportion to GOMAXPROCS. The executable is equivalent to go fmt. It is free, included in the Go installation, and distributed under a BSD-style license.
Spec sheet
- Purpose
- Gofmt automatically formats Go programs using tabs for indentation and blanks for alignment.Read 1 Oct 2026 · go.dev
- Platforms
- The Go compiler toolchain can target AIX, Android, DragonFly BSD, FreeBSD, Illumos, Linux, macOS/iOS, NetBSD, OpenBSD, Plan 9, Solaris, and Windows.Read 1 Oct 2026 · go.dev
- Security
- The Go project issues security fixes to the two most recent major Go releases and provides a security policy for reporting vulnerabilities.Read 1 Oct 2026 · go.dev
- Support
- Questions about using Go or announcements relevant to Go users should be sent to the golang-nuts mailing list.Read 1 Oct 2026 · go.dev
- License
- Go is an open source project distributed under a BSD-style license.Read 1 Oct 2026 · go.dev
- Comment formatting
- Gofmt reformats Go documentation comments into canonical paragraphs, lists, headings, links, and code blocks.Read 1 Oct 2026 · go.dev
- Distribution
- The Go installation process installs an executable called gofmt, equivalent to go fmt.Read 1 Oct 2026 · go.dev
- Editor integrations
- The Go project documents gofmt integrations for Vim, Emacs, Eclipse, Sublime Text, Git pre-commit hooks, and Mercurial.Read 1 Oct 2026 · go.dev
- Formatting options
- Its flags include displaying diffs, listing files with formatting differences, applying rewrite rules, simplifying code, and reporting all errors.Read 1 Oct 2026 · go.dev
- Input handling
- Without an explicit path, gofmt processes standard input; with a directory, it recursively processes .go files while ignoring files beginning with a period.Read 1 Oct 2026 · go.dev
- Output
- By default, gofmt prints reformatted sources to standard output.Read 1 Oct 2026 · go.dev
- Performance
- Since Go 1.18, gofmt reads and formats input files concurrently with memory limited proportionally to GOMAXPROCS.Read 1 Oct 2026 · go.dev
- Source transformation
- The -r flag applies rewrite rules whose patterns and replacements are valid Go expressions.Read 1 Oct 2026 · go.dev
Plans and prices
Strong points and limits
Strong points
- Included in Go installations at no listed charge
- Processes .go files recursively in directories
- Can show diffs and identify files needing formatting
- Documented integrations include editors and Git hooks
Limits
- Formats Go programs only
- Directory processing skips files beginning with a period
Who it suits
gofmt suits Go developers who want consistent source formatting from the command line or through documented editor and version-control integrations. Its file and rewrite options also support batch formatting and code transformations.
Verdict
gofmt provides a standard formatter with options for reviewing changes, simplifying code, and applying rewrite rules. It is a focused command-line tool for Go source rather than a general-purpose formatter.
Where Specifiction places it
- Code Formatting Tools#13 of 347.8