golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.93k stars 17.52k forks source link

x/tools/cmd/vet: warn about unused non-exported functions #4827

Closed griesemer closed 7 years ago

griesemer commented 11 years ago
It's common to leave dead functions in larger packages as a result of refactoring over
time. go vet could issue warnings (some functions we may want to leave for debugging).

More generally, this could apply to all top-level consts, types, vars, and funcs - at
least to some extent.
griesemer commented 11 years ago

Comment 1:

I should have said "unexported" dead functions. It does require for go vet to run over
all files of a package.
rsc commented 11 years ago

Comment 2:

[The time for maybe has passed.]
rsc commented 11 years ago

Comment 4:

Labels changed: added priority-later, go1.2maybe, removed priority-triage.

rsc commented 11 years ago

Comment 5:

Labels changed: added feature.

robpike commented 11 years ago

Comment 6:

Status changed to Started.

robpike commented 11 years ago

Comment 7:

Labels changed: removed go1.2maybe.

robpike commented 11 years ago

Comment 8:

Status changed to Accepted.

rsc commented 10 years ago

Comment 9:

Labels changed: added go1.3maybe.

rsc commented 10 years ago

Comment 10:

Labels changed: removed feature.

rsc commented 10 years ago

Comment 11:

Labels changed: added release-none, removed go1.3maybe.

rsc commented 10 years ago

Comment 12:

Labels changed: added repo-tools.

mewmew commented 10 years ago

Comment 13:

This has probably been mentioned elsewhere, but I'll include a link here for future
reference.
Rémy has implemented some dead code detection at:
https://github.com/remyoudompheng/go-misc/blob/master/deadcode/deadcode.go
JayNakrani commented 7 years ago

Do we need this? If so, I could work on it in 1.9. Let me know.

minux commented 7 years ago

IMHO, probably ok as an optional vet check, but as gri mentioned, it will give false positive on debug functions, so we can't make it part of the default checks.

Also note the check has to take test files and excluded files (via build tags) into consideration too. Such a test would be nice, but I think it's too complicated to get 100% right.

robpike commented 7 years ago

I think it's probably too hard to get the false positives rate low enough in the real world.

It might work as a lint check, which can be looser.

Closing.

rsc commented 7 years ago

I think that might be too much even for lint, but if anyone does want this check, https://github.com/dominikh/go-unused already does it.