mirror of
https://github.com/Crocmagnon/fatcontext.git
synced 2024-11-21 15:38:08 +01:00
detects nested contexts in loops
a0fa7dbcdc
updates: - [github.com/pre-commit/pre-commit-hooks: v2.3.0 → v4.5.0](https://github.com/pre-commit/pre-commit-hooks/compare/v2.3.0...v4.5.0) - [github.com/golangci/golangci-lint: v1.57.1 → v1.57.2](https://github.com/golangci/golangci-lint/compare/v1.57.1...v1.57.2) |
||
---|---|---|
.github/workflows | ||
cmd/fatcontext | ||
contrib | ||
pkg/analyzer | ||
testdata/src | ||
.gitignore | ||
.golangci.yml | ||
.goreleaser.yaml | ||
.pre-commit-config.yaml | ||
go.mod | ||
go.sum | ||
LICENSE | ||
Makefile | ||
README.md |
fatcontext
fatcontext
is a Go linter which detects potential fat contexts in loops.
They can lead to performance issues, as documented here: https://gabnotes.org/fat-contexts/
Example
package main
import "context"
func ok() {
ctx := context.Background()
for i := 0; i < 10; i++ {
ctx := context.WithValue(ctx, "key", i)
_ = ctx
}
}
func notOk() {
ctx := context.Background()
for i := 0; i < 10; i++ {
ctx = context.WithValue(ctx, "key", i) // "nested context in loop"
_ = ctx
}
}
Development
Setup pre-commit locally:
pre-commit install
Run tests & linter:
make lint test
To release, just publish a git tag:
git tag -a v0.1.0 -m "v0.1.0"
git push --follow-tags