Skip to content
Latchkey

Go "gofmt -l" CI Failures - Fix Unformatted Code

A CI formatting gate runs gofmt -l to list files that are not gofmt-clean. Any file it prints means the code is not formatted to Go’s canonical style, so the gate fails until those files are reformatted.

What this error means

A formatting step fails by printing one or more file paths (the output of gofmt -l) and exiting nonzero. The code compiles and tests pass - only the formatting check fails.

CI log
$ gofmt -l .
internal/store/store.go
cmd/server/main.go
Error: the above files are not gofmt-formatted

Common causes

Code committed without running gofmt

Files were edited and committed without gofmt (or a format-on-save), so they differ from Go’s canonical formatting.

An editor not configured to gofmt Go files

A contributor’s editor does not format Go on save, so their changes land unformatted and the gate catches them.

How to fix it

Format the listed files and commit

Reformat the whole tree (or just the named files) and commit the result.

Terminal
gofmt -w .
git add -u && git commit -m "gofmt"

Make the CI gate explicit

Fail clearly when any file is unformatted, printing exactly which ones.

.github/workflows/ci.yml
test -z "$(gofmt -l .)" || { gofmt -l .; echo 'run gofmt -w .'; exit 1; }

How to prevent it

  • Run gofmt -w . (or format on save) before committing.
  • Keep the gofmt -l gate in CI so drift is caught in PRs.
  • Commit an .editorconfig and enable gofmt-on-save in editors.

Frequently asked questions

What causes ""gofmt" needs to be run"?
Files were edited and committed without gofmt (or a format-on-save), so they differ from Go’s canonical formatting.
How do I fix "gofmt" needs to be run?
Reformat the whole tree (or just the named files) and commit the result.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card