detects nested contexts in loops
Find a file
2024-03-27 22:11:46 +01:00
.github/workflows setup linter in github actions 2024-03-27 22:11:46 +01:00
cmd/foreshadow initial commit 2024-03-27 19:24:38 +01:00
contrib add readme 2024-03-27 19:53:02 +01:00
pkg/analyzer fix: don't touch AST 2024-03-27 19:57:23 +01:00
testdata/src initial commit 2024-03-27 19:24:38 +01:00
.gitignore initial commit 2024-03-27 19:24:38 +01:00
.golangci.yml add linter and pre-commit 2024-03-27 22:01:27 +01:00
.pre-commit-config.yaml add linter and pre-commit 2024-03-27 22:01:27 +01:00
go.mod downgrade required go version 2024-03-27 19:31:24 +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 add linter and pre-commit 2024-03-27 22:01:27 +01:00
README.md add readme 2024-03-27 19:53:02 +01:00

foreshadow

foreshadow is a Go linter which detects un-shadowed 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) // "context not shadowed in loop"
		_ = ctx
	}
}