add containedctx linter (#2382)
This commit is contained in:
parent
1685402de9
commit
68f530a81a
1
go.mod
1
go.mod
@ -73,6 +73,7 @@ require (
|
||||
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
|
||||
github.com/shirou/gopsutil/v3 v3.21.12
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/sivchari/containedctx v1.0.1
|
||||
github.com/sivchari/tenv v1.4.7
|
||||
github.com/sonatard/noctx v0.0.1
|
||||
github.com/sourcegraph/go-diff v0.6.1
|
||||
|
2
go.sum
generated
2
go.sum
generated
@ -702,6 +702,8 @@ github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrf
|
||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/sivchari/containedctx v1.0.1 h1:fJq44cX+tD+uT5xGrsg25GwiaY61NGybQk9WWKij3Uo=
|
||||
github.com/sivchari/containedctx v1.0.1/go.mod h1:PwZOeqm4/DLoJOqMSIJs3aKqXRX4YO+uXww087KZ7Bw=
|
||||
github.com/sivchari/tenv v1.4.7 h1:FdTpgRlTue5eb5nXIYgS/lyVXSjugU8UUVDwhP1NLU8=
|
||||
github.com/sivchari/tenv v1.4.7/go.mod h1:5nF+bITvkebQVanjU6IuMbvIot/7ReNsUV7I5NbprB0=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
|
19
pkg/golinters/containedctx.go
Normal file
19
pkg/golinters/containedctx.go
Normal file
@ -0,0 +1,19 @@
|
||||
package golinters
|
||||
|
||||
import (
|
||||
"github.com/sivchari/containedctx"
|
||||
"golang.org/x/tools/go/analysis"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
|
||||
)
|
||||
|
||||
func NewContainedCtx() *goanalysis.Linter {
|
||||
a := containedctx.Analyzer
|
||||
|
||||
return goanalysis.NewLinter(
|
||||
a.Name,
|
||||
a.Doc,
|
||||
[]*analysis.Analyzer{a},
|
||||
nil,
|
||||
).WithLoadMode(goanalysis.LoadModeSyntax)
|
||||
}
|
@ -183,6 +183,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
|
||||
WithPresets(linter.PresetPerformance, linter.PresetBugs).
|
||||
WithURL("https://github.com/timakin/bodyclose"),
|
||||
|
||||
linter.NewConfig(golinters.NewContainedCtx()).
|
||||
WithSince("1.44.0").
|
||||
WithPresets(linter.PresetStyle).
|
||||
WithURL("https://github.com/sivchari/containedctx"),
|
||||
|
||||
linter.NewConfig(golinters.NewContextCheck()).
|
||||
WithSince("v1.43.0").
|
||||
WithPresets(linter.PresetBugs).
|
||||
|
15
test/testdata/containedctx.go
vendored
Normal file
15
test/testdata/containedctx.go
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// args: -Econtainedctx
|
||||
package testdata
|
||||
|
||||
import "context"
|
||||
|
||||
type ok struct {
|
||||
i int
|
||||
s string
|
||||
}
|
||||
|
||||
type ng struct {
|
||||
ctx context.Context // ERROR "found a struct that contains a context.Context field"
|
||||
}
|
||||
|
||||
type empty struct{}
|
Loading…
x
Reference in New Issue
Block a user