golangci-lint "File is not gofmted" - Fix in CI
The gofmt linter inside golangci-lint flags any file that does not match canonical formatting. CI fails on the diff rather than rewriting source, so the fix is to format locally and commit.
What this error means
golangci-lint fails with File is not gofmted with -s (gofmt) pointing at specific lines. Source was committed without running gofmt.
go
main.go:12: File is not "gofmted" with -s (gofmt)Common causes
Code committed unformatted
gofmt was not run before commit, so the file differs from canonical formatting.
Editor not running gofmt on save
A missing format-on-save hook let unformatted code reach the repo.
How to fix it
Format and commit
- Run gofmt with simplification across the tree and commit the result.
shell
gofmt -s -w .Gate formatting in CI
- Fail the build if gofmt would change anything.
.github/workflows/ci.yml
- run: test -z "$(gofmt -s -l .)"How to prevent it
- Enable format-on-save with gofmt -s in your editor.
- Add a gofmt check to CI and to a pre-commit hook.
- Keep the gofmt linter enabled in golangci-lint config.
Related guides
golangci-lint "typecheck" errors - Fix in CIFix golangci-lint "typecheck" errors in CI - the linter could not compile the package, so every analyzer fail…
golangci-lint "Error return value not checked" - Fix in CIFix golangci-lint errcheck "Error return value is not checked" in CI - a returned error was ignored. Handle i…
staticcheck SA1019 "is deprecated" - Fix in CIFix staticcheck SA1019 "X is deprecated" in CI - code uses an API marked deprecated. Migrate to the replaceme…