golangci-lint
golangci-lint copied to clipboard
New linter: flag unnecessary calls to `Finish` on `gomock.Controller`s in Go 1.14+
Your feature request related to a problem? Please describe.
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.
Describe the solution you'd like.
A linting rule that can flag when we're unnecessarily calling .Finish
, when using a Go version of 1.14+
Describe alternatives you've considered.
N/A
Additional context.
No response
Hello,
FYI golangci-lint is a meta-linter, there are no internal linting rules.
That's fair! Are you happy me leaving this here in case someone else wants to pick it up and contribute it?
I flagged it as a linter idea, so yes we can keep it. Can you improve the title of your issue?
Hi can I try implementing a linter based on this idea?
Yes please, happy for you to go for it ☺
Sorry for a bit of delay as I was busy with my uni work. I have finished the implementation part and I will do more testing to ensure that it really works. Once done with it, I will throw a PR.
@daikidev111, how is it going? :)
Pay attention that github.com/golang/mock
is archived and moved under Uber support (github.com/uber-go/mock
).
@Antonboom I've completed 90% of the implementation. However, due to the package having different support now, I'm unsure whether I should finish the implementation and submit a pull request or not. Is it possible to create a linter for a package that isn't natively supported by Go?
Is it possible to create a linter for a package that isn't natively supported by Go?
It has never been supported natively by Go, it was related to a library.
The libraries inside the golang organization are not related to Go itself.
Thank you for the clarification. I will resume working on this!
Hi, look like the interested user still doesn't move forward with this
so I created the linter here https://github.com/hendrywiranto/gomockcontrollerfinish
will open a PR soon to integrate it
also if you guys have other idea for the name I'm still open for it, maybe gomocklint
might be a more suitable name
For the workaround see https://github.com/golangci/golangci-lint/pull/4202#issuecomment-1824345449
@ldez maybe we should close this issue because it's possible to detect Finish
calls with forbidigo
?