This Go tool is a static analysis utility that scans your source code for interfaces and reports their complexity based on method count. It is particularly useful for identifying big interfaces that might violate the Interface Segregation Principle.
A command-line tool that parses Go source files to locate interface definitions, counts their methods, and displays them in a sorted list.
- Recursive Scanning: Walks through directories to find all
.gofiles. - Static Analysis: Uses the standard
go/astandgo/parserlibraries (no reflection required). - Filtering: Filter results by minimum method count or limit to a "top N" list.
- Smart Defaults: Automatically ignores the
vendor/directory unless specified otherwise. - Detailed Output: Shows the interface name, method count, and the exact file/line number.
git clone https://github.com/wasmup/gofacecount.git
cd gofacecountgo install github.com/wasmup/gofacecount@latest
# or
CGO_ENABLED=0 go install -x -ldflags=-s
go version -m $(which gofacecount)go build Run the tool against a directory (defaults to current directory if none provided):
gofacecount [flags] [path]
gofacecount
gofacecount -top 10
gofacecount -top 10 -min 5
gofacecount -vendor -top 10| Flag | Type | Description |
|---|---|---|
-top |
int |
Only print the top X results (sorted by highest method count). |
-min |
int |
Only print interfaces with at least X methods. |
-vendor |
bool |
Include the vendor/ folder in the scan (default: false). |
Find all interfaces in the current directory:
gofacecount .
Find the top 5 largest interfaces:
gofacecount -top 5
Find interfaces with 10 or more methods:
gofacecount -min 10
gofacecount -top 10
Rank | Meths | Interface Name | Location
------------------------------------------------------------------------------------------
1 | 37 | Type | reflect/type.go:40
2 | 23 | TB | testing/testing.go:881
3 | 22 | Node | cmd/compile/internal/ir/node.go:19
4 | 18 | TestingT | runtime/importx_test.go:11
5 | 17 | Object | go/types/object.go:29
6 | 17 | Object | cmd/compile/internal/types2/object.go:26
7 | 17 | testingT | context/context_test.go:16
8 | 15 | testDeps | testing/testing.go:2192
9 | 14 | Context | cmd/internal/dwarf/dwarf.go:192
10 | 13 | testingT | time/abs_test.go:7
The tool utilizes the Abstract Syntax Tree (AST) to traverse the code structure:
- Walk: Recursively visits files in the provided path.
- Parse: Converts Go source into an AST via
go/parser. - Inspect: Targets
ast.TypeSpecnodes specifically looking for*ast.InterfaceType. - Sort: Orders results primarily by method count (descending) and secondarily by name.