-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
enable shadow from govet #1863
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
enable shadow from govet #1863
Conversation
1fb5fbb
to
4abc98f
Compare
bb5cdd2
to
cf19b6d
Compare
0428808
to
fe79a5c
Compare
Sorry for the delayed review. I’m in favor of adding linting for shadowing. However, after reading this PR twice, I still feel that applying it to For example, take the following code: if err := common.Sleep(ctx, interval); err != nil { Changing it to: err := common.Sleep(ctx, interval)
if err != nil { feels a bit much. The former is a common idiom in Go and makes it clear that we're only dealing with the Since |
I'm wondering if using this form will work if err := common.Sleep(ctx, interval); err != nil { Let's give this a try |
It works. The issue comes often from the very first err that is define in the scope, that implies everything else will be reported as shadowed. The solution is to use the |
defd80f
to
d155442
Compare
The solution is described here |
861306d
to
2bc9ec4
Compare
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.
Sorry for the very late reply. I've been thinking about this for a while. It's true that detecting variable shadowing has many advantages, however I still believe that universally disallowing shadowing of err
hurts code readability.
We've had various discussions and you've made several changes to the PR, but I don't think my stance on this has changed. I truly appreciate your dedicated contributions.
e00867a
to
13b3d0c
Compare
72a3411
to
484de74
Compare
rules: | ||
- text: 'shadow: declaration of "err" shadows declaration at line' | ||
linters: | ||
- govet |
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.
I followed @ccoVeille advice and rolled-back err
related changes. Shall I just close this PR or does it fits better your expectations @shirou ?
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
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.
Thank you for the thoughtful discussion and updates. I've reviewed the changes, and I believe they are now clear and understandable. I will go ahead and merge the PR.
Description
This enable and fixes shadow rule from govet.