noctx
finds function calls without context.Context.
Passing context.Context
enables library user to cancel request, getting trace information and so on.
noctx
helps you to identify code that could be rewritten to use the context.Context.
go vet is a Go standard tool for analyzing source code.
- Install noctx.
$ go install github.com/sonatard/noctx/cmd/noctx@latest
- Execute noctx
$ go vet -vettool=`which noctx` main.go
./main.go:6:11: net/http.Get must not be called
golangci-lint is a fast Go linters runner.
-
Install golangci-lint. golangci-lint - Install
-
Setup .golangci.yml
# Add noctx to enable linters.
linters:
enable:
- noctx
# Or enable-all is true.
linters:
default: all
disable:
- xxx # Add unused linter to disable linters.
- Execute noctx
# Use .golangci.yml
$ golangci-lint run
# Only execute noctx
golangci-lint run --enable-only noctx
Lines 41 to 50 in b768dab
Lines 26 to 39 in b768dab
noctx/testdata/src/network/net.go
Line 17 in b768dab
Lines 52 to 66 in b768dab
Line 18 in b768dab
Lines 71 to 74 in b768dab
noctx/testdata/src/crypto_tls/tls.go
Line 17 in b768dab
Lines 68 to 69 in b768dab
noctx/testdata/src/exec_cmd/exec.go
Line 11 in b768dab