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.
$ gofmt -l .
internal/store/store.go
cmd/server/main.go
Error: the above files are not gofmt-formattedCommon 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.
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.
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 -lgate in CI so drift is caught in PRs. - Commit an
.editorconfigand enable gofmt-on-save in editors.