Skip to content
Merged
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
Prev Previous commit
Next Next commit
fix: importShadow
  • Loading branch information
ldez committed Apr 1, 2025
commit 20686056e028e08ca76665dd461f184541a5c2c2
11 changes: 11 additions & 0 deletions pkg/golinters/gocritic/gocritic.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (w *goCriticWrapper) init(logger logutils.Log, settings *config.GoCriticSet

settingsWrapper := newSettingsWrapper(settings, logger)
settingsWrapper.InferEnabledChecks()

// Validate must be after InferEnabledChecks, not before.
// Because it uses gathered information about tags set and finally enabled checks.
if err := settingsWrapper.Validate(); err != nil {
Expand All @@ -113,7 +114,17 @@ func (w *goCriticWrapper) run(pass *analysis.Pass) error {

linterCtx.SetPackageInfo(pass.TypesInfo, pass.Pkg)

needFileInfo := slices.ContainsFunc(enabledCheckers, func(c *gocriticlinter.Checker) bool {
// Related to https://github.com/go-critic/go-critic/blob/440ff466685b41e67d231a1c4a8f5e093374ee93/checkers/importShadow_checker.go#L23
return strings.EqualFold(c.Info.Name, "importShadow")
})

for _, f := range pass.Files {
if needFileInfo {
// Related to https://github.com/go-critic/go-critic/blob/440ff466685b41e67d231a1c4a8f5e093374ee93/checkers/importShadow_checker.go#L23
linterCtx.SetFileInfo(f.Name.Name, f)
}

runOnFile(pass, f, enabledCheckers)
}

Expand Down