-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Shadowed Variable Checking is Broken with Default Settings #1008
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
Comments
Specifically, it looks like this line is lying to the userbase: |
I have the same issue, and it doesn't work to enable it explicitly in my own But from what I can see @Zamiell the |
@Zamiel The file https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml does not contain the default options, it's just an example of all options, so there is no meaning for this configuration. @torbjornvatn the The linter seems to work as expected: no problempackage main
import "fmt"
func main() {
a := 1
fmt.Println(a)
if true {
a := 2
fmt.Println(a)
}
} problempackage main
import "fmt"
func main() {
a := 1
if true {
a := 2
fmt.Println(a)
}
fmt.Println(a)
}
|
@ldez
found my logic error., I was expecting next code to trigger package testdataabstract
import (
"context"
ctxpkg "context"
"fmt"
)
func ReadFromContext(context context.Context) context.Context {
return ctxpkg.WithValue(context, "key", "val")
} |
|
I was thinking that I already answered your questions #1008 (comment)
because there is no bug, the behavior is expected.
It's not a bug,
because in your example there is no shadowing. no shadowpackage main
import "fmt"
func main() {
a := 1
fmt.Println(a)
if true {
a := 2
fmt.Println(a)
}
} shadowpackage main
import "fmt"
func main() {
a := 1
if true {
a := 2
fmt.Println(a)
}
fmt.Println(a)
}
Because it's not enabled by default in govet. |
Ah, ok, I see. Thanks for the quick reply Idez. |
Thank you for creating the issue!
Please include the following information:
Version of golangci-lint
Config file
Go environment
Verbose output of running
Description of the Problem
I'm using the following "main.go" file:
Question 1 - Obviously, I am shadowing a variable in the above code snippet. If I am not mistaken, this should be caught by govet. So something seems broken, because according to the documentation in the README.md file, the "vetshadow" linter is supposed to be enabled by default. What gives?
Question 2 - Poking around in the default options, I noticed that it has the following specification for govet:
Can someone explain why does it simultaneously says
check-shadowing: true
anddisable: -shadow
? Is that a bug? If it is not a bug, can we add a comment or something and explain what the heck is going on there?The text was updated successfully, but these errors were encountered: