Documentation
¶
Overview ¶
Package main lints a module for functions no program reaches. Run from the module's root, it runs deadcode's analysis twice, on one load of the module: from the main packages alone, and with the tests as well. The module's build flags, as GOFLAGS sets them, apply to the load. Code that only its own tests still call is dead all the same, so a function must be reachable from a main package, or be marked as test support with a doc comment line that starts with the marker and gives the reason:
// deadcode:testonly, since the tests of other packages fake with it.
The marker can go on a package's doc comment instead, for a package that exists for tests, such as a fake. A marked function must still be called by some test, and must not be reachable from a main package, so that a marker can't outlive its reason.
deadcode keeps every method of a type that converts to an interface, and every method of the interface, so it misses methods nothing calls behind one, such as the queries sqlc generates. deadlint also reports each exported method whose name no non-test code selects: every interface method, and every concrete one unless it satisfies an interface of another module, through which that module may call it. The predeclared error counts as one, and so does the error chain that errors.Is, errors.As and errors.Unwrap call through interfaces of their own: Unwrap() error, Unwrap() []error, Is(error) bool and As(any) bool. The methods of an interface in a generated file are skipped, since they mirror a concrete type's and a generated file can't carry a marker; a generated type's methods, such as sqlc's queries, are still checked. The marker covers these too, and such a method must then be selected by a test.
Source Files
¶
- deadcode.go
- main.go
- unselected.go