fatcontext

module
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2025 License: MIT

README

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

Directories

Path Synopsis
cmd
fatcontext command
Package main runs the analyzer.
Package main runs the analyzer.
pkg
analyzer
Package analyzer contains everything related to the linter analysis.
Package analyzer contains everything related to the linter analysis.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL