Skip to content

Fix failed_prerequisites error #944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/lint/linter/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package linter

import (
"go/ast"

"golang.org/x/tools/go/packages"

"github.com/golangci/golangci-lint/internal/pkgcache"
Expand Down Expand Up @@ -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{}
}
4 changes: 4 additions & 0 deletions pkg/lint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down