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
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions pkg/lint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,29 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
}
}()

// pkgs will get dirty while analyzing, which affects to other linters' result.
// To avoid this issue, we clone the loaded packages rather than directly using them.
oldPackages := lintCtx.Packages
oldOriginalPackages := lintCtx.OriginalPackages
clone := func(pkgs []*gopackages.Package) []*gopackages.Package {
clonedPkgs := make([]*gopackages.Package, len(pkgs))
for i, pkg := range pkgs {
p := *pkg
clonedPkgs[i] = &p
}
return clonedPkgs
}
lintCtx.Packages = clone(lintCtx.Packages)
lintCtx.OriginalPackages = clone(lintCtx.OriginalPackages)

specificLintCtx := *lintCtx
specificLintCtx.Log = r.Log.Child(lc.Name())

issues, err := lc.Linter.Run(ctx, &specificLintCtx)

lintCtx.Packages = oldPackages
lintCtx.OriginalPackages = oldOriginalPackages

if err != nil {
return nil, err
}
Expand Down