-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: add nakedefer linter #3282
base: master
Are you sure you want to change the base?
Conversation
Hey, thank you for opening your first Pull Request ! |
In order for a pull request adding a linter to be reviewed, the linter and the PR must follow some requirements. Pull Request Description
Linter
The Linter Tests Inside Golangci-lint
|
Hello, maybe I have missed something: why only IMO using a function that returns something (not only a function) for a defer is a problem. |
@ldez sometimes we're using factory for deferred functions, this linter tracks situation when deferred function returns a function and ensures that returned function is invoked, i.e. |
Overall you're right, and maybe we have to make the linter stricter🤔 |
Hello! |
@rawen17 you have to sign the CLA #3282 (comment) |
I've signed it already |
The email that you are using to commit is not set up in your GitHub account, so you haven't signed. |
Sorry, now is signed |
@rawen17, please, select more specific naming.
Moreover, it would be great to see among the examples something less abstract and closer to real life. Now it raise more questions than answers. E.g., why is it invalid? func funcDeferAnonymousReturnIntAndErr() {
defer func() (int, error) { // want "deferred call should not return anything"
return 1, nil
}()
} If you explain more clearly the reason of the linter, I can help with the name. Thanks 👍 |
@Antonboom, hi!
May be i misunderstood your question |
Okay, does the linter ignore I propose something like:
|
Curious about this as well. If not, I see a lot of this pattern incoming: defer func() {
_, _ = whatIActuallyWanted()
}() |
In test/testdata/defer.go there are 2 examples funcReturnErr - can be like
|
Change name linter 'defer' to 'nakedefer' |
@rawen17 can you rebase and fix the conflict? |
@rawen17 why did you close the PR? |
No, it is my fault, i will try fix it |
yes you can reopen this PR, but you need to add commits 😉 |
@ldez Hello! |
83cada1
to
d7e6791
Compare
Sorry for the late reply. I share the point of view of @bombsimon maybe it can be a good idea to add |
Could you please add default value for I run linter on large code base and receive warnings about: defer t.Stop() // *time.Timer
defer response.Body.Close()
defer db.Close() // *pg.DB P.S. It's also cool to not ignore README badges like "Go Report", "CI Build Status", etc. P.P.S. Could be helpful
|
nakedefer
is a linter that finds defer functions which return anything.https://github.com/GaijinEntertainment/go-nakedefer