Skip to content

Commit 4c4918f

Browse files
committed
contextcheck: bump to v1.0.5 && add noCache flag
1 parent a8b4bda commit 4c4918f

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ require (
8383
github.com/spf13/viper v1.10.1
8484
github.com/ssgreg/nlreturn/v2 v2.2.1
8585
github.com/stretchr/testify v1.7.0
86-
github.com/sylvia7788/contextcheck v1.0.4
86+
github.com/sylvia7788/contextcheck v1.0.5
8787
github.com/tdakkota/asciicheck v0.1.1
8888
github.com/tetafro/godot v1.4.11
8989
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/contextcheck.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"golang.org/x/tools/go/analysis"
66

77
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
"github.com/golangci/golangci-lint/pkg/lint/linter"
89
)
910

1011
func NewContextCheck() *goanalysis.Linter {
@@ -14,5 +15,9 @@ func NewContextCheck() *goanalysis.Linter {
1415
"check the function whether use a non-inherited context",
1516
[]*analysis.Analyzer{analyzer},
1617
nil,
17-
).WithLoadMode(goanalysis.LoadModeTypesInfo)
18+
).WithLoadMode(goanalysis.LoadModeTypesInfo).WithNoCache().
19+
WithContextSetter(func(lintCtx *linter.Context) {
20+
analyzer.Run = contextcheck.NewRun(lintCtx.Packages)
21+
})
22+
1823
}

pkg/golinters/goanalysis/linter.go

+10
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Linter struct {
4949
contextSetter func(*linter.Context)
5050
loadMode LoadMode
5151
needUseOriginalPackages bool
52+
noCache bool
5253
}
5354

5455
func NewLinter(name, desc string, analyzers []*analysis.Analyzer, cfg map[string]map[string]interface{}) *Linter {
@@ -86,6 +87,11 @@ func (lnt *Linter) WithContextSetter(cs func(*linter.Context)) *Linter {
8687
return lnt
8788
}
8889

90+
func (lnt *Linter) WithNoCache() *Linter {
91+
lnt.noCache = true
92+
return lnt
93+
}
94+
8995
func (lnt *Linter) Name() string {
9096
return lnt.name
9197
}
@@ -187,6 +193,10 @@ func (lnt *Linter) getLoadMode() LoadMode {
187193
return lnt.loadMode
188194
}
189195

196+
func (lnt *Linter) withoutCache() bool {
197+
return lnt.noCache
198+
}
199+
190200
func allFlagNames(fs *flag.FlagSet) []string {
191201
var ret []string
192202
fs.VisitAll(func(f *flag.Flag) {

pkg/golinters/goanalysis/metalinter.go

+9
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,12 @@ func (ml MetaLinter) getAnalyzerToLinterNameMapping() map[*analysis.Analyzer]str
8888
}
8989
return analyzerToLinterName
9090
}
91+
92+
func (ml MetaLinter) withoutCache() bool {
93+
for _, l := range ml.linters {
94+
if l.withoutCache() {
95+
return true
96+
}
97+
}
98+
return false
99+
}

pkg/golinters/goanalysis/runners.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type runAnalyzersConfig interface {
2525
useOriginalPackages() bool
2626
reportIssues(*linter.Context) []Issue
2727
getLoadMode() LoadMode
28+
withoutCache() bool
2829
}
2930

3031
func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Issue, error) {
@@ -41,7 +42,11 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss
4142
pkgs = lintCtx.OriginalPackages
4243
}
4344

44-
issues, pkgsFromCache := loadIssuesFromCache(pkgs, lintCtx, cfg.getAnalyzers())
45+
var issues []result.Issue
46+
var pkgsFromCache map[*packages.Package]bool
47+
if !cfg.withoutCache() {
48+
issues, pkgsFromCache = loadIssuesFromCache(pkgs, lintCtx, cfg.getAnalyzers())
49+
}
4550
var pkgsToAnalyze []*packages.Package
4651
for _, pkg := range pkgs {
4752
if !pkgsFromCache[pkg] {
@@ -52,7 +57,7 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss
5257
diags, errs, passToPkg := runner.run(cfg.getAnalyzers(), pkgsToAnalyze)
5358

5459
defer func() {
55-
if len(errs) == 0 {
60+
if len(errs) == 0 && !cfg.withoutCache() {
5661
// If we try to save to cache even if we have compilation errors
5762
// we won't see them on repeated runs.
5863
saveIssuesToCache(pkgs, pkgsFromCache, issues, lintCtx, cfg.getAnalyzers())

0 commit comments

Comments
 (0)