mirror of
https://github.com/Crocmagnon/fatcontext.git
synced 2024-11-21 23:48:10 +01:00
refactor: rename foreshadow to fatcontext
This commit is contained in:
parent
a7ef75e6e9
commit
781d685146
8 changed files with 14 additions and 14 deletions
|
@ -20,7 +20,7 @@ builds:
|
|||
- linux
|
||||
- windows
|
||||
- darwin
|
||||
main: ./cmd/foreshadow
|
||||
main: ./cmd/fatcontext
|
||||
|
||||
archives:
|
||||
- format: tar.gz
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -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
2
go.mod
|
@ -1,4 +1,4 @@
|
|||
module github.com/Crocmagnon/foreshadow
|
||||
module github.com/Crocmagnon/fatcontext
|
||||
|
||||
go 1.21
|
||||
|
||||
|
|
|
@ -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 `:=`",
|
||||
|
|
|
@ -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"
|
||||
|
|
6
testdata/src/example.go
vendored
6
testdata/src/example.go
vendored
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue