Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add local imported packages to the packages to analyze when using cache #4424

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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)
ldez marked this conversation as resolved.
Show resolved Hide resolved

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

defer func() {
Expand Down
Loading