diff --git a/.goreleaser.yaml b/.goreleaser.yaml index ef67dc7..26756b1 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -20,7 +20,7 @@ builds: - linux - windows - darwin - main: ./cmd/foreshadow + main: ./cmd/fatcontext archives: - format: tar.gz diff --git a/README.md b/README.md index cbeb082..2d36d83 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# foreshadow +# fatcontext -`foreshadow` is a Go linter which detects un-shadowed contexts in loops. +`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/ ## Example @@ -23,7 +23,7 @@ func notOk() { ctx := context.Background() for i := 0; i < 10; i++ { - ctx = context.WithValue(ctx, "key", i) // "context not shadowed in loop" + ctx = context.WithValue(ctx, "key", i) // "nested context in loop" _ = ctx } } diff --git a/cmd/foreshadow/main.go b/cmd/fatcontext/main.go similarity index 72% rename from cmd/foreshadow/main.go rename to cmd/fatcontext/main.go index 2ecee9e..3fb44e7 100644 --- a/cmd/foreshadow/main.go +++ b/cmd/fatcontext/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/Crocmagnon/foreshadow/pkg/analyzer" + "github.com/Crocmagnon/fatcontext/pkg/analyzer" "golang.org/x/tools/go/analysis/singlechecker" ) diff --git a/contrib/example.go b/contrib/example.go index f8d416b..fb02931 100644 --- a/contrib/example.go +++ b/contrib/example.go @@ -15,7 +15,7 @@ func notOk() { ctx := context.Background() for i := 0; i < 10; i++ { - ctx = context.WithValue(ctx, "key", i) // "context not shadowed in loop" + ctx = context.WithValue(ctx, "key", i) // "nested context in loop" _ = ctx } } diff --git a/go.mod b/go.mod index 6dd1ee7..e41e61b 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/Crocmagnon/foreshadow +module github.com/Crocmagnon/fatcontext go 1.21 diff --git a/pkg/analyzer/analyzer.go b/pkg/analyzer/analyzer.go index df58bb9..98c577c 100644 --- a/pkg/analyzer/analyzer.go +++ b/pkg/analyzer/analyzer.go @@ -12,8 +12,8 @@ import ( ) var Analyzer = &analysis.Analyzer{ - Name: "foreshadow", - Doc: "enforce context shadowing inside loops", + Name: "fatcontext", + Doc: "detects nested contexts in loops", Run: run, Requires: []*analysis.Analyzer{inspect.Analyzer}, } @@ -63,7 +63,7 @@ func run(pass *analysis.Pass) (interface{}, error) { pass.Report(analysis.Diagnostic{ Pos: assignStmt.Pos(), - Message: "context not shadowed in loop", + Message: "nested context in loop", SuggestedFixes: []analysis.SuggestedFix{ { Message: "replace `=` with `:=`", diff --git a/pkg/analyzer/analyzer_test.go b/pkg/analyzer/analyzer_test.go index 7a8a228..3dfbe5f 100644 --- a/pkg/analyzer/analyzer_test.go +++ b/pkg/analyzer/analyzer_test.go @@ -1,7 +1,7 @@ package analyzer_test import ( - "github.com/Crocmagnon/foreshadow/pkg/analyzer" + "github.com/Crocmagnon/fatcontext/pkg/analyzer" "golang.org/x/tools/go/analysis/analysistest" "os" "path/filepath" diff --git a/testdata/src/example.go b/testdata/src/example.go index d3a8096..69777f7 100644 --- a/testdata/src/example.go +++ b/testdata/src/example.go @@ -11,18 +11,18 @@ func example() { } for i := 0; i < 10; i++ { - ctx = context.WithValue(ctx, "key", i) // want "context not shadowed in loop" + ctx = context.WithValue(ctx, "key", i) // want "nested context in loop" ctx = context.WithValue(ctx, "other", "val") } for item := range []string{"one", "two", "three"} { - ctx = wrapContext(ctx) // want "context not shadowed in loop" + ctx = wrapContext(ctx) // want "nested context in loop" ctx := context.WithValue(ctx, "key", item) ctx = wrapContext(ctx) } for { - ctx = wrapContext(ctx) // want "context not shadowed in loop" + ctx = wrapContext(ctx) // want "nested context in loop" break } }