detects nested contexts in loops
Find a file
2024-03-27 23:50:12 +01:00
.github/workflows docs: update & document dev commands 2024-03-27 22:59:32 +01:00
cmd/fatcontext refactor: rename foreshadow to fatcontext 2024-03-27 23:50:12 +01:00
contrib refactor: rename foreshadow to fatcontext 2024-03-27 23:50:12 +01:00
pkg/analyzer refactor: rename foreshadow to fatcontext 2024-03-27 23:50:12 +01:00
testdata/src refactor: rename foreshadow to fatcontext 2024-03-27 23:50:12 +01:00
.gitignore chore: setup goreleaser 2024-03-27 22:48:14 +01:00
.golangci.yml add linter and pre-commit 2024-03-27 22:01:27 +01:00
.goreleaser.yaml refactor: rename foreshadow to fatcontext 2024-03-27 23:50:12 +01:00
.pre-commit-config.yaml ci: skip go test in pre-commit.ci 2024-03-27 23:07:39 +01:00
go.mod refactor: rename foreshadow to fatcontext 2024-03-27 23:50:12 +01:00
go.sum initial commit 2024-03-27 19:24:38 +01:00
LICENSE add LICENSE 2024-03-27 20:04:07 +01:00
Makefile Revert "ci: run go checks in pre-commit.ci" 2024-03-27 23:07:11 +01:00
README.md refactor: rename foreshadow to fatcontext 2024-03-27 23:50:12 +01:00

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