-
-
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
The "unused" linting rule has misleading behaviour when interacting with generated code #3354
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Right—apologies for the noise above. I've replaced the example with something that should be clearer. |
Hello,
|
Oh! I didn't realise that was what was meant by "standalone"; golangci-lint seems to stand alone quite well... I've reproduced the same issues with staticcheck, so I'll port this across to there. Thanks for the pointer! |
Welcome
Description of the problem
Notice
The issue has been lifted to the staticcheck repository. The issue can be found here.
Original description
One of the default linters, unused, is described on the golangci-lint site as something that
but if a constant, variable, function, or type is only referred to in a generated file, then golangci-lint will act in a misleading way.
I think this should be categorised as a bug, but it may be that I've missed a piece of configuration that I can set.
Version of golangci-lint
Configuration file
Go environment
The reproducing example at the end uses a Dockerfile.
Verbose output of running
The reproducing example at the end uses a Dockerfile.
Code example or link to a public repository
The "details" block below describes the following directory structure (which I've also attached as a tarball here):
First, recreate this directory structure and set
rc.sh
to be executable.If you run
./rc.sh
, then golangci-lint will report that the functionfoo
is unused.If you remove the first line from bar.go (that says the file is generated) and then run
./rc.sh
, then golangci-lint will now report that bothfoo
andbar
are unused.If you replace
bar
withBar
, then, irrespective of the line at the top about the file being generated being present, everything is (correctly) declared as being used.In my view, the messages in 1 and 2 are misleading. In both cases, the issue is that
bar
isn't public (and therefore isn't used);foo
is only unused as a consequence ofbar
not being used. This is especially awkward in 1, because there's no way to resolve the problem from the error message alone.The text was updated successfully, but these errors were encountered: