gomocklinter
A linter that checks the usage of go mocking libraries
Note: The original golang/mock package is archived and the maintained fork is go.uber.org/mock.
This linter supports both.
Installation & usage
$ go install github.com/hendrywiranto/gomocklinter@latest
$ gomocklinter ./...
or build the binary and use go vet
$ go build -o gomocklinter main.go
$ go vet -vettool=./gomocklinter ./...
Motivation
As highlighted in https://pkg.go.dev/github.com/golang/mock/gomock#NewController
New in go1.14+, if you are passing a *testing.T into this function you no longer need to call ctrl.Finish() in your test methods.
Examples
// Bad
func TestFoo(t *testing.T) {
mock := gomock.NewController(t)
defer mock.Finish() // no need to call this since go1.14
}
// Good
func TestFoo(t *testing.T) {
mock := gomock.NewController(t)
}