@@ -3,6 +3,7 @@ package goanalysis
3
3
import (
4
4
"fmt"
5
5
"runtime"
6
+ "slices"
6
7
"sort"
7
8
"strings"
8
9
"sync"
@@ -42,14 +43,32 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss
42
43
pkgs = lintCtx .OriginalPackages
43
44
}
44
45
46
+ pkgByPath := make (map [string ]* packages.Package , len (pkgs ))
47
+ for _ , pkg := range pkgs {
48
+ pkgByPath [pkg .PkgPath ] = pkg
49
+ }
50
+
45
51
issues , pkgsFromCache := loadIssuesFromCache (pkgs , lintCtx , cfg .getAnalyzers ())
52
+
46
53
var pkgsToAnalyze []* packages.Package
47
54
for _ , pkg := range pkgs {
48
55
if ! pkgsFromCache [pkg ] {
49
56
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 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
+ }
50
66
}
51
67
}
52
68
69
+ // keep only unique packages
70
+ pkgsToAnalyze = slices .Compact (pkgsToAnalyze )
71
+
53
72
diags , errs , passToPkg := runner .run (cfg .getAnalyzers (), pkgsToAnalyze )
54
73
55
74
defer func () {
0 commit comments