finishgomock

package module
v0.0.0-...-998f26e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2023 License: MIT Imports: 5 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "finishgomock",
	Doc:  doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL