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@latestYou 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 calledOr run it directly.
uncalled ./...
# github.com/stevenh/go-uncalled/test
test/bad.go:10:2: rows.Err() must be calledSee 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- printsuncalledversion information and exits.-verbose [level]- configuresuncalledlogging level, without a level it increments, with a level it sets (default:info)
Each rule is defined by the following common configuration.
- name:
stringname of this rule. - disabled:
booldisable this rule. - category:
stringcategory to log failures with. - packages:
[]stringlist of package import paths that if present will trigger this rule to be processed. - results:
[]objectlist of results that methods return that if matched will trigger this rule to be processed.- type:
stringname of the type relative to the package. - pointer:
boolif true this type is a pointer type. - expect:
objectthe details to expect when performing checks.- call:
stringthe method that should be called on the returned type, blank if this is a direct function call. - args:
[]stringthe 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: falseYou can find more info in the available rules.
This code was inspired by the following analysers: