GitXplorerGitXplorer
b

punused

public
39 stars
6 forks
2 issues

Commits

List of commits on branch main.
Verified
0b038cf8f1b8db9f851a44619c83f0b5598c24e1

Make it work without arguments

bbep committed 3 years ago
Verified
98761b1cf34c41c6005beca0fa4232a747c052ce

Improve tests, fix logic for struct methods

bbep committed 3 years ago
Verified
eca94e20b4a022c223888a77d68c0aadb8ba90da

Handle a tree of symbols

bbep committed 3 years ago
Verified
50ffa70caf3984cfe100026b66c4c9c60574a9b9

github: Add FUNDING.yml

bbep committed 3 years ago
Verified
386582c767582ca1212da29c7ca8e991120361fc

readme: Add build badge

bbep committed 3 years ago
Verified
e71a399b720648c8bbb5b2bd9b09b1cd988b1936

github: Test with -race flag

bbep committed 3 years ago

README

The README file for this repository.

Go

This is a small utility that finds unused exported Go symbols (functions, methods ...) in Go. For all other similar use cases, use https://github.com/dominikh/go-tools

I have used this in Hugo (a monorepo with many packages), and it works, but there are some caveats:

  • It does not detect references from outside of your project.
  • It does not detect references via reflect.
  • Some possible surprises when it comes to interfaces.

So, you should inspect and test the proposed deletes. See this test repo for more information.

Install

go install github.com/bep/punused@latest

You also need gopls:

go install golang.org/x/tools/gopls@latest

Use

punused takes only one (optional) argument: A Glob filename pattern (Unix style slashes, double asterisk is supported) of Go files to check.

punused needs to be run from the root of a Go Module. To test a specific package you can target it with a Glob, e.g. punused "utils/*.go".

Running punused in this repository currently gives:

punused                                                                
internal/lib/gopls.go:125:2 field Detail is unused (EU1002)
internal/lib/gopls.go:135:2 field Tags is unused (EU1002)
internal/lib/gopls.go:141:2 field Deprecated is unused (EU1002)
internal/lib/gopls.go:147:2 field Range is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:7:2 variable UnusedVar is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:12:2 constant UnusedConst is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:19:6 function UnusedFunction is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:25:2 field UnusedField is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:32:15 method (MyType).UnusedMethod is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:36:6 interface UnusedInterfaceWithUsedAndUnusedMethod is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:38:2 method UnusedInterfaceMethodReturningInt is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:37:2 method UsedInterfaceMethodReturningInt is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:41:6 interface UnusedInterface is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:42:2 method UnusedInterfaceReturningInt is unused (EU1002)
internal/lib/testpackages/firstpackage/code1.go:45:6 interface UsedInterface is unused (EU1002)
internal/lib/testpackages/firstpackage/testlib1.go:4:2 constant OnlyUsedInTestConst is used in test only (EU1001)

Note that we currently skip checking test code, but you do warned about unused symbols only used in tests (see example above).