Skip to content

Commit 5999fb0

Browse files
authored
Merge pull request #944 from ksoichiro/fix-failed_prerequisites-error
Fix failed_prerequisites error
2 parents 7a95e5a + 796b4ff commit 5999fb0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pkg/lint/linter/context.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package linter
22

33
import (
4+
"go/ast"
5+
46
"golang.org/x/tools/go/packages"
57

68
"github.com/golangci/golangci-lint/internal/pkgcache"
@@ -30,3 +32,18 @@ type Context struct {
3032
func (c *Context) Settings() *config.LintersSettings {
3133
return &c.Cfg.LintersSettings
3234
}
35+
36+
func (c *Context) ClearTypesInPackages() {
37+
for _, p := range c.Packages {
38+
clearTypes(p)
39+
}
40+
for _, p := range c.OriginalPackages {
41+
clearTypes(p)
42+
}
43+
}
44+
45+
func clearTypes(p *packages.Package) {
46+
p.Types = nil
47+
p.TypesInfo = nil
48+
p.Syntax = []*ast.File{}
49+
}

pkg/lint/runner.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
114114
specificLintCtx := *lintCtx
115115
specificLintCtx.Log = r.Log.Child(lc.Name())
116116

117+
// Packages in lintCtx might be dirty due to the last analysis,
118+
// which affects to the next analysis.
119+
// To avoid this issue, we clear type information from the packages.
120+
specificLintCtx.ClearTypesInPackages()
117121
issues, err := lc.Linter.Run(ctx, &specificLintCtx)
118122
if err != nil {
119123
return nil, err

0 commit comments

Comments
 (0)