Skip to content
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

chore(lint): disable shadowing checks with govet #1940

Merged
merged 4 commits into from
Nov 2, 2021

Conversation

qdm12
Copy link
Contributor

@qdm12 qdm12 commented Oct 28, 2021

Changes

  • Disable shadowing check (disabled by default) with govet
  • In my opinion:
    • these make the code longer since we need to pre-declare things
    • you can't have locally-scoped variables in an if or for block for example if the variable name is already used in the upper scope.

Feel free to comment & close it if you disagree with the change 😉

Tests

golangci-lint run

Issues

  • No issue

Primary Reviewer

  • No-one

Copy link
Contributor

@jimjbrettj jimjbrettj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. When I first joined I was having this happen to me with "err" specifically but we wanted to have consistent error variable names (which makes sense), so I'm a fan of this change

@codecov
Copy link

codecov bot commented Oct 28, 2021

Codecov Report

Merging #1940 (b0fc726) into development (becec9e) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##           development    #1940   +/-   ##
============================================
  Coverage        60.26%   60.26%           
============================================
  Files              180      180           
  Lines            18189    18189           
============================================
  Hits             10962    10962           
  Misses            5415     5415           
  Partials          1812     1812           
Flag Coverage Δ
unit-tests 60.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update becec9e...b0fc726. Read the comment docs.

Copy link
Contributor

@kishansagathiya kishansagathiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having this happen to me with "err" specifically but we wanted to have consistent error variable names (which makes sense).

I think, generally, the shadowing check appears when you are doing something like k, err :=, where err is an old variable. (Is that right, or am I confusing with some other check)

Personally, it isn't a big pain for me to declare the variable separately to avoid this warning.

The check is, however, helpful, because it ensures that you are not using a different copy of some variable (err is getting re-initialized in above example). I have faced at least one bug because of this, and this check could prevent stuff like that.

you can't have locally-scoped variables in an if or for block for example if the variable name is already used in the upper scope.

Using a different variable name is less confusing for reader.

@noot
Copy link
Contributor

noot commented Oct 29, 2021

I agree with Kishan, I don't see this check as bad, it's helped catch bugs in the past. sure it can be annoying, but I'd rather have to declare a variable separately than have some bug

@qdm12
Copy link
Contributor Author

qdm12 commented Oct 29, 2021

Using a different variable name is less confusing for reader.

Definitely. Although my problem is more about err. I'm not going to use a different error variable name for every error returned 😄 And that means I always have to add a line to define variables before a line returning an error, this is really slowing me down and adds code.

To illustrate

a, err := f()
// ...
var b int
b, err = g()
// above you cannot do b, err := g() 😢

EDIT: I'll check you might be able to disable it for errors using the exclude rules

@qdm12 qdm12 force-pushed the qdm12-golangcilint-shadowing branch from 4cc5616 to 4d7afb9 Compare November 1, 2021 14:47
@qdm12
Copy link
Contributor Author

qdm12 commented Nov 1, 2021

Shadowing detection is re-enabled, but shadow detection of errors (err) is disabled.

@qdm12 qdm12 force-pushed the qdm12-golangcilint-shadowing branch from 586cb03 to b372ed4 Compare November 1, 2021 22:56
@qdm12 qdm12 merged commit d2334e3 into development Nov 2, 2021
@qdm12 qdm12 deleted the qdm12-golangcilint-shadowing branch November 2, 2021 16:32
@github-actions
Copy link

github-actions bot commented Dec 3, 2021

🎉 This PR is included in version 0.6.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

timwu20 pushed a commit to timwu20/gossamer that referenced this pull request Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants