π Lightning-fast static analyzer that hunts down unused interface methods in your Go codebase
unused-interface-methods is a powerful static analysis tool for Go that detects interface methods that are declared but never used anywhere in your codebase. Built on top of golang.org/x/tools/go/analysis, it seamlessly integrates with your development workflow.
- π§Ή Clean APIs: Dead interface methods confuse users and bloat your public API
- β‘ Faster Builds: Removing unused code makes compilation faster
- π§ Easier Refactoring: Less surface area = simpler maintenance
- π¦ CI-Ready: Non-zero exit status when issues are found
package some_name
// Partially implemented interface
type Interface interface {
SomeMethod()
UnusedMethod() // unused for SomeObject - can be removed
}
type SomeObject struct {
i Interface
}
func (o *SomeObject) SomeMethod() {
o.i.SomeMethod() // definitely used interface method
}- π― Smart Detection: Finds unused methods on ordinary and generic interfaces (Go 1.18+)
- π§ Context-Aware: Understands complex usage patterns:
- π Method values & function pointers
- π Type assertions & type switches
- π¦ Embedded interfaces (bidirectional)
- π¨οΈ
fmtpackage implicitString()calls
- π Clean Output: Sorted by file path and line numbers
- π Editor Integration: Works with
go vet,gopls, and your favorite IDE - π Cross-Platform: Full support for Windows, Linux, and macOS
# Install the tool globally
go install github.com/unused-interface-methods/unused-interface-methods@latest
unused-interface-methods ./...# unused-interface-methods.yml
ignore:
- "**/*_test.go"
- "test/**"
- "**/*_mock.go"
- "**/mock/**"
- "**/mocks/**"The configuration file is automatically searched in the current directory (or .config/) with an optional dot prefix.
Ctrl+Shift+P (Cmd+Shift+P on Mac) β "Tasks: Run Task" β "Go: Check Unused Interface Methods"
- β Real-time highlighting of unused interface methods
- β Problems panel integration with clickable errors
- β File explorer markers showing files with issues
π Optional: Install the Trigger Task on Save extension to automatically run the task silently on file save.
path/interfaces.go:41:2: method "OnError" of interface "EventHandler" is declared but not used
path/interfaces.go:42:2: method "Subscribe" of interface "EventHandler" is declared but not used
path/interfaces.go:43:2: method "UnSubscribe" of interface "EventHandler" is declared but not used
π‘ Pro Tip: Output format is identical to
go vet- your editor will highlight issues automatically!
import (
"golang.org/x/tools/go/analysis"
"github.com/unused-interface-methods/unused-interface-methods"
)
// Add to your multichecker
analyzers := []*analysis.Analyzer{
unusedInterfaceMethods.Analyzer,
// ... other analyzers
}# Install golangci-lint
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Clone and build
git clone https://github.com/unused-interface-methods/unused-interface-methods.git
cd unused-interface-methods
make build- πͺ Reflection: Cannot track
reflect.Value.Call()usage - π Plugins: Runtime plugin loading is not tracked
- π§ͺ Generics: Best-effort matching; edge cases may slip through
We β€οΈ contributions! Please include:
- π Reproducer (code snippet or minimal repo)
- π Expected vs actual output
- π Go version (
go version)
π¬ PRs are welcome too.
β Star this repo if it helped you write cleaner Go code.