detects nested contexts in loops
Go to file
Gabriel Augendre d5171e1d54
Some checks failed
Go / build (1.21, macos-latest) (push) Has been cancelled
Go / build (1.21, ubuntu-latest) (push) Has been cancelled
Go / build (1.21, windows-latest) (push) Has been cancelled
Go / build (1.22, macos-latest) (push) Has been cancelled
Go / build (1.22, ubuntu-latest) (push) Has been cancelled
Go / build (1.22, windows-latest) (push) Has been cancelled
golangci-lint / lint (1.21) (push) Has been cancelled
golangci-lint / lint (1.22) (push) Has been cancelled
Merge pull request #4 from Crocmagnon/dependabot/go_modules/golang.org/x/tools-0.21.0
build(deps): bump golang.org/x/tools from 0.19.0 to 0.21.0
2024-05-07 10:53:48 +02:00
.github add dependabot config 2024-05-07 10:50:26 +02: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 fix: remove panic 2024-03-28 00:08:19 +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 force github token in goreleaser 2024-03-28 00:01:25 +01:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate 2024-05-06 22:31:22 +00:00
go.mod build(deps): bump golang.org/x/tools from 0.19.0 to 0.21.0 2024-05-07 08:50:53 +00:00
go.sum build(deps): bump golang.org/x/tools from 0.19.0 to 0.21.0 2024-05-07 08:50:53 +00: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 Update README.md 2024-04-06 09:09:43 +02: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/

Installation / usage

fatcontext is available in golangci-lint since v1.58.0.

go install github.com/Crocmagnon/fatcontext/cmd/fatcontext@latest
fatcontext ./...

There are no specific configuration options or custom command-line flags.

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