Skip to content
Latchkey

golangci-lint "File is not `gofmt`-ed with `-s`" in CI

The gofmt linter inside golangci-lint reports that a file does not match gofmt -s output. It is a formatting gate: the code is fine but not simplified/formatted to gofmt's canonical form.

What this error means

golangci-lint reports "File is not gofmt-ed with -s (gofmt)" at specific lines and exits 1. The diff is whitespace, import grouping, or a missed simplification.

golangci-lint
main.go:12:1: File is not `gofmt`-ed with `-s` (gofmt)

Common causes

Code committed without running gofmt

A file was saved by an editor that did not run gofmt on save, so its formatting differs from the canonical gofmt -s output.

The simplify flag exposes extra changes

-s applies simplifications (like dropping redundant type info) beyond plain gofmt, so even gofmt'd code can still be flagged.

How to fix it

Run gofmt with simplify and commit

  1. Run gofmt -s -w . across the module.
  2. Commit the formatting changes.
  3. Re-run golangci-lint to confirm the gofmt linter passes.
Terminal
gofmt -s -w .
golangci-lint run ./...

Format on save and verify in CI

Enable format-on-save with gofmt/goimports locally and keep the gofmt linter enabled so drift is caught.

How to prevent it

  • Run gofmt -s -w (or goimports) before committing.
  • Enable format-on-save in your editor.
  • Keep the gofmt linter enabled in .golangci.yml.

Related guides

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