go-tools icon indicating copy to clipboard operation
go-tools copied to clipboard

unused: flag unused arguments

Open gyuho opened this issue 7 years ago • 5 comments

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!

gyuho avatar Jun 20 '17 18:06 gyuho

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.

mvdan avatar Jun 20 '17 18:06 mvdan

What mvdan said.

dominikh avatar Jun 20 '17 23:06 dominikh

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.

ainar-g avatar Jul 25 '18 10:07 ainar-g

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

dominikh avatar Jul 25 '18 12:07 dominikh

@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.

jirfag avatar Jul 26 '18 08:07 jirfag