Skip to content
Latchkey

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

  1. Run gofmt with simplification across the tree and commit the result.
shell
gofmt -s -w .

Gate formatting in CI

  1. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →