dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.15k stars 373 forks source link

unused: flag unused arguments #124

Open gyuho opened 7 years ago

gyuho commented 7 years ago

Could unused flag unused function arguments?

e.g.

func hello(v int) {
    println(1)
}
// complains that 'v' is not used.

c.f. https://github.com/coreos/etcd/issues/8068

And thanks for the great tool!

mvdan commented 7 years ago

This is an inherently incorrect science, and false positives are likely. I believe this was discarded for unused on purpose. I've written unparam for this, which does an okay job.

dominikh commented 7 years ago

What mvdan said.

ainar-g commented 6 years ago

I know that this issue has been closed for over a year now, and that the official response is "Just use unparam!", but I would like to add some input, as a heavy user of megacheck.

Unused parameters often occur during a refactoring/rapid prototyping. Often, they mask bugs, that will only be discovered at test time (or even production). I would assume that a tool called unused finds unused parameters as well, even if it's behind a flag like -exported, but it doesn't. At all. I already have four tools that I use on every project (six, if you count megacheck as three tools). Adding another one for a feature that unused is missing doesn't sound right.

I don't mean any disrespect towards @mvdan, but I really think this should be a part of unused.

dominikh commented 6 years ago

I'll reconsider it for the rewrite of unused, although I'd be inclined to limit it to unexported functions only.

jirfag commented 6 years ago

@ainar-g 5 linters isn’t a problem: you can use gometalinter or similar tool: it makes running of even dozens of linters easy. And they will run in parallel by these tools.