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

Ignore variable declaration if it's the zero value #39

Open
natefinch opened this issue Mar 3, 2022 · 4 comments
Open

Ignore variable declaration if it's the zero value #39

natefinch opened this issue Mar 3, 2022 · 4 comments

Comments

@natefinch
Copy link

At work, we are working on updating all our linting, and one of the problems we have hit with wastedassign is that code like this gets flagged:

isFoo := false
// ...

isFoo, err := bar.Baz()

Now, I know that you should probably write var isFoo bool ... but it's not technically incorrect, and almost assuredly does not indicate an error, just someone who is used to other languages. It would be great if there were a way to avoid flagging that kind of a line so that we can use it for the other cases when it is much more likely to indicate a bug.

@ericleb010
Copy link

I agree, and the error returned makes it a bit confusing to understand what the issue is exactly. Especially if someone isn't familiar with relying on a primitive's zero value.

@egonelbre
Copy link

I hit this as well with:

buildType := ""

@drshriveer
Copy link

This really would be great to fix. I personally use name := defaultValue over var name type because it makes it exceptionally clear what the start value is. If nothing else, I'd love a configuration flag for this.

@jadeGopher
Copy link

Agreed with @drshriveer.
Declaration err := error(nil) is similar to var err error and I personally prefer first option but linter tells that is wasted assign.

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

No branches or pull requests

5 participants