Skip to content

Commit bb41e54

Browse files
committed
Fix failed_prerequisites error
1 parent 45f1e48 commit bb41e54

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pkg/lint/runner.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,29 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
111111
}
112112
}()
113113

114+
// pkgs will get dirty while analyzing, which affects to other linters' result.
115+
// To avoid this issue, we clone the loaded packages rather than directly using them.
116+
oldPackages := lintCtx.Packages
117+
oldOriginalPackages := lintCtx.OriginalPackages
118+
clone := func(pkgs []*gopackages.Package) []*gopackages.Package {
119+
clonedPkgs := make([]*gopackages.Package, len(pkgs))
120+
for i, pkg := range pkgs {
121+
p := *pkg
122+
clonedPkgs[i] = &p
123+
}
124+
return clonedPkgs
125+
}
126+
lintCtx.Packages = clone(lintCtx.Packages)
127+
lintCtx.OriginalPackages = clone(lintCtx.OriginalPackages)
128+
114129
specificLintCtx := *lintCtx
115130
specificLintCtx.Log = r.Log.Child(lc.Name())
116131

117132
issues, err := lc.Linter.Run(ctx, &specificLintCtx)
133+
134+
lintCtx.Packages = oldPackages
135+
lintCtx.OriginalPackages = oldOriginalPackages
136+
118137
if err != nil {
119138
return nil, err
120139
}

0 commit comments

Comments
 (0)