detects nested contexts in loops
Find a file
dependabot[bot] 3947c6f8d5
Some checks failed
Go / build (push) Has been cancelled
golangci-lint / lint (push) Has been cancelled
Go / coverage (push) Has been cancelled
build(deps): bump golang.org/x/tools from 0.28.0 to 0.29.0
Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.28.0 to 0.29.0.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.28.0...v0.29.0)

---
updated-dependencies:
- dependency-name: golang.org/x/tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-17 01:09:26 +01:00
.github chore: groups github action updates 2025-01-17 00:57:15 +01:00
cmd/fatcontext feat: better discriminate assignations to struct pointers 2025-01-17 00:02:58 +01:00
pkg/analyzer tests: add tests on suggested fixes 2025-01-17 00:54:35 +01:00
.gitignore chore: ignore binary 2024-09-01 13:40:56 +02:00
.golangci.yml chore: format with goimports 2024-11-20 15:56:39 +01:00
.goreleaser.yaml fix(goreleaser): draft release 2025-01-14 17:33:18 +01:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate 2025-01-07 07:49:41 +01:00
go.mod build(deps): bump golang.org/x/tools from 0.28.0 to 0.29.0 2025-01-17 01:09:26 +01:00
go.sum build(deps): bump golang.org/x/tools from 0.28.0 to 0.29.0 2025-01-17 01:09:26 +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 feat: better discriminate assignations to struct pointers 2025-01-17 00:02:58 +01:00

fatcontext

Go Reference Go Report Card Go Coverage

fatcontext is a Go linter which detects potential fat contexts in loops or function literals. 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 ./...

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