go-format

command module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 2 Imported by: 0

README

go-format

Go Reference Go Report Card License

go-format is an opinionated Go formatter for codebases that already use gofmt, but still want more readable line wrapping and vertical spacing.

It runs:

  • gofmt
  • pinned golines for long-line wrapping
  • gofumpt
  • a logical blank-line pass for dense functions

The blank-line pass separates guard clauses, validation and normalization, setup/defer cleanup blocks, decision branches, lock groups, loops/switches, and final returns. It keeps coupled value, err := call() / if err != nil pairs together and keeps leading comments attached to the statement they describe. It does not insert blank lines between every statement.

Installation

go install github.com/stremovskyy/go-format@latest

For reproducible CI, install or run a tagged version:

go run github.com/stremovskyy/go-format@v0.1.0 --check ./...

Usage

Format the current directory:

go-format --write ./...

Check formatting in CI:

go-format --check ./...

Use a different target line length:

go-format --write --max-len 100 ./...

Skip golines when only gofmt, gofumpt, and logical blank lines are wanted:

go-format --write --skip-golines ./...

Format editor input from stdin:

go-format --stdin --stdin-path internal/cli/cli.go < internal/cli/cli.go

List files that would change without printing diffs:

go-format --check --list --diff=false ./...

Print the bundled formatter versions:

go-format --version

More examples and before/after comparisons are in docs/examples.md.

Behavior

go-format recursively discovers .go files under the provided paths and skips:

  • generated files with Code generated ... DO NOT EDIT
  • .git
  • vendor
  • third_party
  • node_modules
  • hidden directories unless --include-hidden is set

--check prints unified diffs and exits with status 1 when files need formatting. Use --diff=false to suppress diffs and --list to print changed file paths. --write rewrites files in place and can also use --list.

--stdin formats source from standard input and writes the formatted source to standard output. It accepts --stdin-path so parse errors and formatter subprocesses can use a meaningful file name.

The first run may download the pinned golines module into the local Go module cache. Use --skip-golines for environments that must avoid that subprocess. Use --skip-readability to disable only the logical blank-line pass.

Release

Releases use semver tags:

git tag v0.1.0
git push origin v0.1.0

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL