Merge pull request #944 from ksoichiro/fix-failed_prerequisites-error
Fix failed_prerequisites error
This commit is contained in:
commit
5999fb0b0a
@ -1,6 +1,8 @@
|
|||||||
package linter
|
package linter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go/ast"
|
||||||
|
|
||||||
"golang.org/x/tools/go/packages"
|
"golang.org/x/tools/go/packages"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/internal/pkgcache"
|
"github.com/golangci/golangci-lint/internal/pkgcache"
|
||||||
@ -30,3 +32,18 @@ type Context struct {
|
|||||||
func (c *Context) Settings() *config.LintersSettings {
|
func (c *Context) Settings() *config.LintersSettings {
|
||||||
return &c.Cfg.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{}
|
||||||
|
}
|
||||||
|
@ -114,6 +114,10 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
|
|||||||
specificLintCtx := *lintCtx
|
specificLintCtx := *lintCtx
|
||||||
specificLintCtx.Log = r.Log.Child(lc.Name())
|
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)
|
issues, err := lc.Linter.Run(ctx, &specificLintCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user