Skip to content

daikieng/finishgomock

Repository files navigation

finishgomock

finishgomock is a golang linter that detects an unnecessary goMock Finish on gomock.Controller. As per the official document for gomock, it is not required to call ctrl.Finish() in a test method that uses goMock controller object anymore (only applied from go 1.14+). This linter is designed in a way that it flags and outputs an error when ctrl.Finish() is used in a test method, which achieves a reduction of unnecessary code. For more details, please visit the official document: https://pkg.go.dev/github.com/golang/mock/gomock#NewController

Installation

go get -u github.com/daikidev111/finishgomock/cmd/finishgomock

Usage

package main

import (
	"testing"

	"github.com/golang/mock/gomock"
)

func fail(t *testing.T) {
	mock := gomock.NewController(t)
	mock.Finish()
}

func failSecond(t *testing.T) {
	mock := gomock.NewController(t)
	defer mock.Finish()
}

func pass(t *testing.T) {
	gomock.NewController(t)
}
go vet -vettool=(which finishgomock) ./...

# output

CI

GitHub Actions

- name: install finishgomock
  run: go install github.com/daikidev111/finishgomock/cmd/finishgomock
- name: exec finishgomock
  run: go vet -vettool=`which finishgomock` ./...

CircleCI

- run:
    name: install finishgomock
    command: go install github.com/daikidev111/finishgomock/cmd/finishgomock
- run:
    name: exec finishgomock
    command: go vet -vettool=`which finishgomock` ./...

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages