-
Notifications
You must be signed in to change notification settings - Fork 298
Add redundant-test-main-exit rule #1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @semihbkgr thank you for tha PR.
I' ve left some comments.
One more thing, we should only apply the rule if the code under analysis is on a Go version 1.15 or higher. To do so, you can take inspiration in other rules like range-val-in_closure
revive/rule/range_val_in_closure.go
Line 17 in 8cb2599
if file.Pkg.IsAtLeastGo122() { |
(that should also be tested)
Thanks again
|
||
pkg := id.Name | ||
fn := fc.Sel.Name | ||
if isCallToExitFunction(pkg, fn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isCallToExitFunction
will return true
even for function calls other than os.Exit
(for example log.Fatal
, log.Panic
...) That behavior is okay for what we check here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @chavacava, thank you for your detailed review and suggestions!
I’m not entirely sure about including logging functions other than os.Exit
or syscall.Exit
. It’s uncommon (in my experience) to call logging functions that internally invoke Exit, but I don't see any downside to including them in this check.
What’s your opinion on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with including logging functions is that the common failure message may not be appropriate for them, as these functions are not necessarily redundant: they first log a message and then exit.
Merged! Thank you @semihbkgr (and @alexandear) |
The
redundant-test-main-exit
rule reports unnecessaryExit
calls inTestMain
functions, as the Go test runner has handled termination automatically since Go 1.15; the details are explained in the issue.fixes #1189
The
deep-exit
rule currently excludes reportingExit
calls inTestMain
functions, but we could consider updating its behavior to include these calls, which might eliminate the need to define this new rule.