Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/golinters/goanalysis/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package goanalysis
import (
"fmt"
"runtime"
"slices"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -42,14 +43,32 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss
pkgs = lintCtx.OriginalPackages
}

pkgByPath := make(map[string]*packages.Package, len(pkgs))
for _, pkg := range pkgs {
pkgByPath[pkg.PkgPath] = pkg
}

issues, pkgsFromCache := loadIssuesFromCache(pkgs, lintCtx, cfg.getAnalyzers())

var pkgsToAnalyze []*packages.Package
for _, pkg := range pkgs {
if !pkgsFromCache[pkg] {
pkgsToAnalyze = append(pkgsToAnalyze, pkg)

// Also add the local packages imported by a package to analyze.
// Some linters produce reports on a package reported by another one.
// This is only needed for local imports.
for _, v := range pkg.Imports {
if p, found := pkgByPath[v.PkgPath]; found {
pkgsToAnalyze = append(pkgsToAnalyze, p)
}
}
}
}

// keep only unique packages
pkgsToAnalyze = slices.Compact(pkgsToAnalyze)

diags, errs, passToPkg := runner.run(cfg.getAnalyzers(), pkgsToAnalyze)

defer func() {
Expand Down