go-uncalled is a static analysis tool for golang which checks for missing calls.
It is compatible with both standard and generic functions as introduced by golang version 1.18.
You can install the uncalled
cmd using go install
command.
go install github.com/stevenh/go-uncalled/cmd/uncalled@latest
You run uncalled
with go vet.
go vet -vettool=$(which uncalled) ./...
# github.com/stevenh/go-uncalled/test
test/bad.go:10:2: rows.Err() must be called
Or run it directly.
uncalled ./...
# github.com/stevenh/go-uncalled/test
test/bad.go:10:2: rows.Err() must be called
See command line options for more details.
uncalled
validates that code to ensure expected calls are made.
uncalled
supports the following command line options
-config <file>
- configures the YAML file to read the configuration from. (default: embedded .uncalled.yaml).-version
- printsuncalled
version information and exits.-verbose [level]
- configuresuncalled
logging level, without a level it increments, with a level it sets (default:info
)
Each rule is defined by the following common configuration.
- name:
string
name of this rule. - disabled:
bool
disable this rule. - category:
string
category to log failures with. - packages:
[]string
list of package import paths that if present will trigger this rule to be processed. - results:
[]object
list of results that methods return that if matched will trigger this rule to be processed.- type:
string
name of the type relative to the package. - pointer:
bool
if true this type is a pointer type. - expect:
object
the details to expect when performing checks.- call:
string
the method that should be called on the returned type, blank if this is a direct function call. - args:
[]string
the list of arguments that the call takes.
- call:
- type:
Example
rules:
# Checks for missing sql Rows.Err() calls.
- name: sql-rows-err
disabled: false
category: sql
packages:
- database/sql
- github.com/jmoiron/sqlx
results:
- type: .Rows
pointer: true
expect:
call: .Err
args: []
- type: error
pointer: false
You can find more info in the available rules.
This code was inspired by the following analysers: