@@ -3,6 +3,7 @@ package goanalysis
33import (
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
4243pkgs = 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+
4551issues ,pkgsFromCache := loadIssuesFromCache (pkgs ,lintCtx ,cfg .getAnalyzers ())
52+
4653var pkgsToAnalyze []* packages.Package
4754for _ ,pkg := range pkgs {
4855if ! pkgsFromCache [pkg ] {
4956pkgsToAnalyze = 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+
5372diags ,errs ,passToPkg := runner .run (cfg .getAnalyzers (),pkgsToAnalyze )
5473
5574defer func () {