Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 849f21e

Browse files
committed
fix: add local imported packages to the packages to analyze when using cache
1 parent 3452e2e commit 849f21e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎pkg/golinters/goanalysis/runners.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package goanalysis
33
import (
44
"fmt"
55
"runtime"
6+
"slices"
67
"sort"
78
"strings"
89
"sync"
@@ -42,14 +43,32 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss
4243
pkgs = lintCtx.OriginalPackages
4344
}
4445

46+
pkgByPath := make(map[string]*packages.Package, len(pkgs))
47+
for _, pkg := range pkgs {
48+
pkgByPath[pkg.PkgPath] = pkg
49+
}
50+
4551
issues, pkgsFromCache := loadIssuesFromCache(pkgs, lintCtx, cfg.getAnalyzers())
52+
4653
var pkgsToAnalyze []*packages.Package
4754
for _, pkg := range pkgs {
4855
if !pkgsFromCache[pkg] {
4956
pkgsToAnalyze = append(pkgsToAnalyze, pkg)
57+
58+
// Also add the local packages imported by a package to analyze.
59+
// Some linters produce reports on a package by reported by another one.
60+
// This is only needed for local imports.
61+
for _, v := range pkg.Imports {
62+
if p, found := pkgByPath[v.PkgPath]; found {
63+
pkgsToAnalyze = append(pkgsToAnalyze, p)
64+
}
65+
}
5066
}
5167
}
5268

69+
// keep only unique packages
70+
pkgsToAnalyze = slices.Compact(pkgsToAnalyze)
71+
5372
diags, errs, passToPkg := runner.run(cfg.getAnalyzers(), pkgsToAnalyze)
5473

5574
defer func() {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /