Skip to content

A linter that checks the usage of go mocking libraries

License

Notifications You must be signed in to change notification settings

hendrywiranto/gomocklinter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gomocklinter

CI Go Report Card Coverage Status MIT License

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

Autofix

Autofix is supported that will delete the entire line with .Finish() call to gomock.Controller

$ ./gomocklinter -fix ./...

Please note that, there may be some adjustments need to be done by hand after this action

// Before
func TestFoo(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish() // will be deleted entirely
}

// After
func TestFoo(t *testing.T) {
	ctrl := gomock.NewController(t)	
}

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) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish() // no need to call this since go1.14
}

// Good
func TestFoo(t *testing.T) {
	ctrl := gomock.NewController(t)
}

About

A linter that checks the usage of go mocking libraries

Topics

Resources

License

Stars

Watchers

Forks