Merge pull request #944 from ksoichiro/fix-failed_prerequisites-error

Fix failed_prerequisites error
This commit is contained in:
Aleksandr Razumov 2020-02-03 00:49:20 +03:00 committed by GitHub
commit 5999fb0b0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -1,6 +1,8 @@
package linter
import (
"go/ast"
"golang.org/x/tools/go/packages"
"github.com/golangci/golangci-lint/internal/pkgcache"
@ -30,3 +32,18 @@ type Context struct {
func (c *Context) Settings() *config.LintersSettings {
return &c.Cfg.LintersSettings
}
func (c *Context) ClearTypesInPackages() {
for _, p := range c.Packages {
clearTypes(p)
}
for _, p := range c.OriginalPackages {
clearTypes(p)
}
}
func clearTypes(p *packages.Package) {
p.Types = nil
p.TypesInfo = nil
p.Syntax = []*ast.File{}
}

View File

@ -114,6 +114,10 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
specificLintCtx := *lintCtx
specificLintCtx.Log = r.Log.Child(lc.Name())
// Packages in lintCtx might be dirty due to the last analysis,
// which affects to the next analysis.
// To avoid this issue, we clear type information from the packages.
specificLintCtx.ClearTypesInPackages()
issues, err := lc.Linter.Run(ctx, &specificLintCtx)
if err != nil {
return nil, err