@@ -10,6 +10,7 @@ import (
1010 "github.com/golangci/golangci-lint/pkg/config"
1111 "github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
1212 "github.com/golangci/golangci-lint/pkg/lint/linter"
13+ "github.com/golangci/golangci-lint/pkg/logutils"
1314 "github.com/golangci/golangci-lint/pkg/result"
1415)
1516
@@ -40,6 +41,9 @@ func NewForbidigo(settings *config.ForbidigoSettings) *goanalysis.Linter {
4041 },
4142 }
4243
44+ // Without AnalyzeTypes, LoadModeSyntax is enough.
45+ // But we cannot make this depend on the settings and have to mirror the mode chosen in GetAllSupportedLinterConfigs,
46+ // therefore we have to use LoadModeTypesInfo in all cases.
4347 return goanalysis .NewLinter (
4448 forbidigoName ,
4549 "Forbids identifiers" ,
@@ -55,16 +59,34 @@ func runForbidigo(pass *analysis.Pass, settings *config.ForbidigoSettings) ([]go
5559 forbidigo .OptionExcludeGodocExamples (settings .ExcludeGodocExamples ),
5660 // disable "//permit" directives so only "//nolint" directives matters within golangci-lint
5761 forbidigo .OptionIgnorePermitDirectives (true ),
62+ forbidigo .OptionAnalyzeTypes (settings .AnalyzeTypes ),
5863 }
5964
60- forbid , err := forbidigo .NewLinter (settings .Forbid , options ... )
65+ // Convert patterns back to strings because that is what NewLinter accepts.
66+ var patterns []string
67+ for _ , pattern := range settings .Forbid {
68+ buffer , err := pattern .MarshalString ()
69+ if err != nil {
70+ return nil , err
71+ }
72+ patterns = append (patterns , string (buffer ))
73+ }
74+
75+ forbid , err := forbidigo .NewLinter (patterns , options ... )
6176 if err != nil {
6277 return nil , fmt .Errorf ("failed to create linter %q: %w" , forbidigoName , err )
6378 }
6479
6580 var issues []goanalysis.Issue
6681 for _ , file := range pass .Files {
67- hints , err := forbid .RunWithConfig (forbidigo.RunConfig {Fset : pass .Fset }, file )
82+ runConfig := forbidigo.RunConfig {
83+ Fset : pass .Fset ,
84+ DebugLog : logutils .Debug (logutils .DebugKeyForbidigo ),
85+ }
86+ if settings != nil && settings .AnalyzeTypes {
87+ runConfig .TypesInfo = pass .TypesInfo
88+ }
89+ hints , err := forbid .RunWithConfig (runConfig , file )
6890 if err != nil {
6991 return nil , fmt .Errorf ("forbidigo linter failed on file %q: %w" , file .Name .String (), err )
7092 }
0 commit comments