deadlint

command module
v0.0.0-...-fd32d70 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

deadlint

deadlint lints a Go module for functions no program reaches. It runs the analysis of deadcode twice, on one load of the module: from the main packages alone, and with the tests as well. The build flags that GOFLAGS sets, such as -tags, 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:

// Helper builds a store for tests.
//
// deadcode:testonly, since the tests of other packages fake with it.
func Helper() *Store {

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. A method of the same name with another signature is still checked. The methods of an interface in a generated file, one with the standard // Code generated ... DO NOT EDIT. header, are skipped, since they mirror a concrete type's, as sqlc's DBTX mirrors *sql.DB, and a generated file can't carry a marker; a generated type's methods, such as sqlc's queries, are still checked, and deadcode itself skips generated files. Names that the module's text templates (.html, .txt and .tmpl files) select, as in {{.Amount.String}}, count as selected. The marker covers these methods too, and such a method must then be selected by a test.

Install

go get -tool evantann.com/deadlint@latest

Use

Run it from the module's root. It takes no flags or arguments:

go tool deadlint

Each problem is printed to stderr, and the command exits 1 when there are any.

Makefile

test-dead:
	go tool deadlint
.PHONY: test-dead

License

GNU Affero General Public License v3.0 or later. See LICENSE.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL