Skip to content

Commit

Permalink
fix: add local imported packages to the packages to analyze when usin…
Browse files Browse the repository at this point in the history
…g cache
  • Loading branch information
ldez committed Mar 7, 2024
1 parent c0f89fb commit 98c486b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/golinters/goanalysis/runners.go
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

0 comments on commit 98c486b

Please sign in to comment.