contextcheck

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

CircleCI

contextcheck

contextcheck is a static analysis tool, it is used to check a function whether use context.Background() or context.TODO() directly instead of the input ctx when calling the sub-function, or even don't pass the ctx, which will result in a broken call link.

For example:

func call1(ctx context.Context) {
    ...
    call2(context.Background()) // should use ctx

    call3() // should pass the ctx
    ...
}

func call2(ctx context.Context) {
    ...
}

func call3() {
    ctx := context.TODO()
    call2(ctx)
}

Installation

You can get contextcheck by go get command.

$ go get -u github.com/sylvia7788/contextcheck

or build yourself.

$ make build
$ make install

Usage

Invoke contextcheck with your package name

$ contextcheck ./...
$ # or
$ contextcheck github.com/you/yourproject/...

Documentation

Index

Constants

View Source
const (
	CtxIn      int = 1 << iota // ctx in function's param
	CtxOut                     // ctx in function's results
	CtxInField                 // ctx in function's field param

	CtxInOut = CtxIn | CtxOut
)

Variables

This section is empty.

Functions

func NewAnalyzer

func NewAnalyzer() *analysis.Analyzer

func NewRun

func NewRun() func(pass *analysis.Pass) (interface{}, error)

Types

This section is empty.

Directories

Path Synopsis
cmd
contextcheck command

Jump to

Keyboard shortcuts

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