GitXplorerGitXplorer
b

punused

public
39 stars
6 forks
2 issues

Commits

List of commits on branch main.
Unverified
4ba0c0989726bc439266910cc11b8be29200004b

github: Update GitHub actions versions

bbep committed 5 months ago
Verified
9287bc573272ea83e3bf5d9fecdc33b791753e71

Update README.md

bbep committed 2 years ago
Verified
48f5af061e3251f3d140b61a817a0eca6871615e

Handle ErrClosed

bbep committed 3 years ago
Verified
3ac3450a77293a9b5bb2a716bc1ca7ca085a50af

Pull the protocl structs into its own file

bbep committed 3 years ago
Unverified
c90c8c74d68f2edaae9963a469a9cdb8eae73c37

Improve tests a little

bbep committed 3 years ago
Verified
cb852cf24dde18b9f68f59d1d94f0190e4436a9b

Module rename unused => punused and some polish

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