Skip to content

Commit ccf27b4

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

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 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy