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

Unused function parameters #1501

Closed
JeremyCraven opened this issue Feb 29, 2024 · 2 comments
Closed

Unused function parameters #1501

JeremyCraven opened this issue Feb 29, 2024 · 2 comments
Labels

Comments

@JeremyCraven
Copy link

JeremyCraven commented Feb 29, 2024

Currently, gopls is catching unused parameters in functions. I want to enforce this in staticcheck as well as that is part of our CI. Running staticcheck does not catch anything on the same code that gopls catches unusedparams (https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/unusedparams#unusedparam)

I searched through the documentation and this is the closest I found to possibly what I'm looking for (#1475). It seems this analyzer is part of staticcheck by default and on so maybe it doesn't work for my use case.

Any suggestions or something I've missed to allow me to catch these unused function parameters with staticcheck?

go version: 1.21.3
gopls version: v0.15.1
staticcheck version: 2023.1.7

@JeremyCraven JeremyCraven added the needs-triage Newly filed issue that needs triage label Feb 29, 2024
@dominikh
Copy link
Owner

I believe this would be #124, but I don't have any plans of working on this in the short term.

You have two easy alternatives:

  1. You can run golang.org/x/tools/gopls/internal/analysis/unusedparams/cmd, which is the standalone version of unusedparam from gopls
  2. You can build a custom version of Staticcheck that includes the unusedparams check. To do so, you would patch and add a call like cmd.AddBareAnalyzers(unusedparams.Analyzer)

Unfortunately, the second option isn't as viable, because the unusedparams analyzer is an internal package and cannot be imported. The first option, on the other hand, is trivial, since you could just use go run golang.org/x/tools/gopls/internal/analysis/unusedparams/cmd@latest ./....

@JeremyCraven
Copy link
Author

Appreciate the super quick and thoughtful response. I can certainly work with that. Thanks again!

@dominikh dominikh added question and removed needs-triage Newly filed issue that needs triage labels Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants