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 Feb 27, 2024
1 parent 3452e2e commit 849f21e
Showing 1 changed file with 19 additions and 0 deletions.
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 by 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 849f21e

Please sign in to comment.