woodpecker/vendor/github.com/sylvia7788/contextcheck
2021-11-16 21:07:53 +01:00
..
.gitignore Add linter bidichk to prevent malicios utf8 chars (#516) 2021-11-16 21:07:53 +01:00
contextcheck.go Add linter bidichk to prevent malicios utf8 chars (#516) 2021-11-16 21:07:53 +01:00
go.mod Add linter bidichk to prevent malicios utf8 chars (#516) 2021-11-16 21:07:53 +01:00
go.sum Add linter bidichk to prevent malicios utf8 chars (#516) 2021-11-16 21:07:53 +01:00
LICENSE Add linter bidichk to prevent malicios utf8 chars (#516) 2021-11-16 21:07:53 +01:00
Makefile Add linter bidichk to prevent malicios utf8 chars (#516) 2021-11-16 21:07:53 +01:00
README.md Add linter bidichk to prevent malicios utf8 chars (#516) 2021-11-16 21:07:53 +01:00

CircleCI

contextcheck

contextcheck is a static analysis tool, it is used to check the function whether use a non-inherited context, which will result in a broken call link.

For example:

func call1(ctx context.Context) {
    ...

    ctx = getNewCtx(ctx)
    call2(ctx) // OK

    call2(context.Background()) // Non-inherited new context, use function like `context.WithXXX` instead

    call3() // Function `call3` should pass the context parameter
    ...
}

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

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

func getNewCtx(ctx context.Context) (newCtx context.Context) {
    ...
    return
}

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
$ go vet -vettool=`which contextcheck` ./...