Skip to content
Latchkey

Go "//go:generate" Directive Ignored - Fix Malformed Directives in CI

go generate only runs comments that match the exact directive form: //go:generate with no space after //, at the start of the line. A stray space (// go:generate) or a misplaced directive is treated as an ordinary comment and silently skipped - so generation appears to "do nothing".

What this error means

go generate ./... runs without error but produces no output and regenerates nothing, or a CI freshness check passes while the generated files are actually stale. The directive is present but malformed, so Go never sees it.

go output
$ go generate ./...
$ # (no output - the directive was ignored)
# the offending line:
// go:generate mockgen -source=store.go   <-- space after // makes it inert

Common causes

A space after // breaks the directive

Go matches //go:generate with no space. // go:generate (with a space) is a normal comment and is never executed.

The directive is not at line start

A //go:generate placed mid-line or indented after code is not recognized; it must begin the line (leading whitespace aside).

How to fix it

Write the directive in the exact form

No space after //, at the start of its own line.

Go
//go:generate mockgen -source=store.go -destination=mock_store.go

Verify the directive actually runs

Terminal
go generate -n ./...   # prints the commands it WOULD run; empty means none matched
go generate -x ./...   # runs and echoes each command

How to prevent it

  • Write //go:generate with no space after the slashes, at line start.
  • Use go generate -n/-x to confirm directives are recognized.
  • Add a CI freshness check that regenerates and diffs.

Frequently asked questions

What causes ""//go:generate" ignored"?
Go matches //go:generate with no space. // go:generate (with a space) is a normal comment and is never executed.
How do I fix "//go:generate" ignored?
No space after //, at the start of its own line.

Related guides

References

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