refactor: rename foreshadow to fatcontext

This commit is contained in:
Gabriel Augendre 2024-03-27 23:50:12 +01:00
parent a7ef75e6e9
commit 781d685146
8 changed files with 14 additions and 14 deletions

View file

@ -20,7 +20,7 @@ builds:
- linux
- windows
- darwin
main: ./cmd/foreshadow
main: ./cmd/fatcontext
archives:
- format: tar.gz

View file

@ -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
}
}

View file

@ -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"
)

View file

@ -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
}
}

2
go.mod
View file

@ -1,4 +1,4 @@
module github.com/Crocmagnon/foreshadow
module github.com/Crocmagnon/fatcontext
go 1.21

View file

@ -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 `:=`",

View file

@ -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"

View file

@ -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
}
}