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 generate ./...
$ # (no output - the directive was ignored)
# the offending line:
// go:generate mockgen -source=store.go <-- space after // makes it inertCommon 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:generate mockgen -source=store.go -destination=mock_store.goVerify the directive actually runs
go generate -n ./... # prints the commands it WOULD run; empty means none matched
go generate -x ./... # runs and echoes each commandHow to prevent it
- Write
//go:generatewith no space after the slashes, at line start. - Use
go generate -n/-xto confirm directives are recognized. - Add a CI freshness check that regenerates and diffs.