detects nested contexts in loops
Find a file
dependabot[bot] bc6bc802c2 build(deps): bump golangci/golangci-lint-action
Bumps the github-actions group with 1 update: [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action).


Updates `golangci/golangci-lint-action` from 6 to 7
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v6...v7)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-02 19:09:31 +02:00
.github build(deps): bump golangci/golangci-lint-action 2025-04-02 19:09:31 +02:00
cmd/fatcontext migrate to golangci-lint v2 and enable stricter linters 2025-04-02 19:07:19 +02:00
pkg/analyzer migrate to golangci-lint v2 and enable stricter linters 2025-04-02 19:07:19 +02:00
.gitignore chore: ignore binary 2024-09-01 13:40:56 +02:00
.golangci.yml migrate to golangci-lint v2 and enable stricter linters 2025-04-02 19:07:19 +02: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-04-02 19:07:19 +02:00
go.mod update minimum go version 2025-04-02 18:39:55 +02:00
go.sum build(deps): bump golang.org/x/tools from 0.30.0 to 0.31.0 2025-04-02 18:39:55 +02: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