-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
unused
linter in golangci-lint reports unused var for named interface param
#1567
Comments
|
That said, this one might be easy enough to fix. |
I already took a look at the code before filing an issue, and it seems pretty straight-forward. I can submit a pull request if you'd like. |
Thank you, but I'm significantly faster at making changes than reviewing and merging PRs. |
👍 I thought that might be the case, but figured I would offer anyway. Just trying to be a good open-source citizen. 😁 |
This feature would be great. unused is much more powerful with When I think about this feature, I also think about type in the error output. Let me demonstrate the usecase. Problem There are common arguments like context.Context in interface methods that are not used by all types of implementations. type I interface {
Do(ctx context.Context, i int, s string) error
}
type Mock struct {}
func (Mock) Do(ctx context.Context, i int, s string) error {
fmt.Println(i, s)
return nil
} the output of unused is:
Solution The desired output returns no errors in the example above. Let me share my 2 solutions to this issue:
|
Hi, @dominikh , any chances that you'll work on this one? I also find |
Eventually, yes. It's not high on my list of priorities, however. |
When declaring an interface method, providing names for the parameters can act as a form of documentation, and is necessary if you want to refer to a parameter in the doc comments. However, it is not possible for the parameter to be "used" because an interface method declaration has no body, so these parameters should not be marked as unused even if the
ParametersAreUsed
option is false. I did not see this issue in earlier versions, so it may be a new behavior since the AST-based rewrite.Note that I am running this through
golangci-lint
because I couldn't figure out a way to configure theParametersAreUsed
option when callingstaticcheck
directly. The version ofgolangci-lint
I am using has a dependency on thehonnef.co/go/tools v0.4.7
module.Lint Command Output
Test Code
main.go
Source Codegolangci-list
ConfigEnvironment Info
The text was updated successfully, but these errors were encountered: