https://github.com/sivchari/containedctx
containedctx is a linter that detects struct contained context.Context field
https://github.com/sivchari/containedctx
go golang golangci-lint linter static-analysis
Last synced: 3 months ago
JSON representation
containedctx is a linter that detects struct contained context.Context field
- Host: GitHub
- URL: https://github.com/sivchari/containedctx
- Owner: sivchari
- License: mit
- Created: 2021-11-28T16:55:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-09T12:15:19.000Z (7 months ago)
- Last Synced: 2025-03-28T18:14:06.458Z (3 months ago)
- Topics: go, golang, golangci-lint, linter, static-analysis
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 19
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# containedctx
[](https://github.com/sivchari/containedctx/actions/workflows/ci.yml)
containedctx is a linter that detects struct contained context.Context field.
This is discouraged technique in favour of passing context as first argument of method or function.
For rationale please read [Contexts and structs](https://go.dev/blog/context-and-structs) the Go blog post.## Instruction
```sh
go install github.com/sivchari/containedctx/cmd/containedctx@latest
```## Usage
```go
package mainimport "context"
type ok struct {
i int
s string
}type ng struct {
ctx context.Context
}type empty struct{}
``````console
go vet -vettool=(which containedctx) ./...# a
./main.go:11:2: found a struct that contains a context.Context field
```## CI
### CircleCI
```yaml
- run:
name: install containedctx
command: go install github.com/sivchari/containedctx/cmd/containedctx- run:
name: run containedctx
command: go vet -vettool=`which containedctx` ./...
```### GitHub Actions
```yaml
- name: install containedctx
run: go install github.com/sivchari/containedctx/cmd/containedctx- name: run containedctx
run: go vet -vettool=`which containedctx` ./...
```