go-uncalled

module
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2022 License: BSD-2-Clause

README

go-uncalled

Reference License Go Report Card

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.

Install

You can install the uncalled cmd using go install command.

go install github.com/stevenh/go-uncalled/cmd/uncalled@latest

How to use

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.

Analyzer

uncalled validates that code to ensure expected calls are made.

Command line

uncalled supports the following command line options

  • -config <file> - configures the YAML file to read the configuration from. (default: embedded .uncalled.yaml).
  • -version - prints uncalled version information and exits.
  • -verbose [level] - configures uncalled logging level, without a level it increments, with a level it sets (default: info)

Rule Configuration

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.
  • methods: []string list of methods that should be present to trigger this rule, empty means no restriction.
  • 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 performaing 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.

Example

rules:
  # Checks for missing sql Rows.Err() calls.
  - name: sql-rows-err
    disabled: false
    category: sql
    packages:
      - database/sql
      - github.com/jmoiron/sqlx
    methods: []
    results:
      - type: .Rows
        pointer: true
        expect:
          call: .Err
          args: []
      - type: error
        pointer: false

You can find more info in the available rules.

Inspired by

This code was inspired by the following analysers:

Directories

Path Synopsis
cmd
uncalled
Command uncalled checks for missing calls.
Command uncalled checks for missing calls.
pkg
uncalled
Package uncalled defines an Analyzer that checks for missing calls.
Package uncalled defines an Analyzer that checks for missing calls.

Jump to

Keyboard shortcuts

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