@@ -10,12 +10,12 @@ 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
1617const forbidigoName = "forbidigo"
1718
18- //nolint:dupl
1919func NewForbidigo (settings * config.ForbidigoSettings ) * goanalysis.Linter {
2020 var mu sync.Mutex
2121 var resIssues []goanalysis.Issue
@@ -40,6 +40,10 @@ func NewForbidigo(settings *config.ForbidigoSettings) *goanalysis.Linter {
4040 },
4141 }
4242
43+ // Without AnalyzeTypes, LoadModeSyntax is enough. But we cannot make
44+ // this depend on the settings and have mirror the mode chosen in
45+ // GetAllSupportedLinterConfigs, therefore we have to use
46+ // LoadModeTypesInfo in all cases.
4347 return goanalysis .NewLinter (
4448 forbidigoName ,
4549 "Forbids identifiers" ,
@@ -56,15 +60,36 @@ func runForbidigo(pass *analysis.Pass, settings *config.ForbidigoSettings) ([]go
5660 // disable "//permit" directives so only "//nolint" directives matters within golangci-lint
5761 forbidigo .OptionIgnorePermitDirectives (true ),
5862 }
63+ if settings != nil && settings .AnalyzeTypes {
64+ options = append (options , forbidigo .OptionAnalyzeTypes (true ))
65+ }
5966
60- forbid , err := forbidigo .NewLinter (settings .Forbid , options ... )
67+ // Convert patterns back to strings because that is what NewLinter
68+ // accepts.
69+ var patterns []string
70+ for _ , pattern := range settings .Forbid {
71+ buffer , err := pattern .String ()
72+ if err != nil {
73+ return nil , err
74+ }
75+ patterns = append (patterns , string (buffer ))
76+ }
77+
78+ forbid , err := forbidigo .NewLinter (patterns , options ... )
6179 if err != nil {
6280 return nil , fmt .Errorf ("failed to create linter %q: %w" , forbidigoName , err )
6381 }
6482
6583 var issues []goanalysis.Issue
6684 for _ , file := range pass .Files {
67- hints , err := forbid .RunWithConfig (forbidigo.RunConfig {Fset : pass .Fset }, file )
85+ runConfig := forbidigo.RunConfig {
86+ Fset : pass .Fset ,
87+ DebugLog : logutils .Debug (logutils .DebugKeyForbidigo ),
88+ }
89+ if settings != nil && settings .AnalyzeTypes {
90+ runConfig .TypesInfo = pass .TypesInfo
91+ }
92+ hints , err := forbid .RunWithConfig (runConfig , file )
6893 if err != nil {
6994 return nil , fmt .Errorf ("forbidigo linter failed on file %q: %w" , file .Name .String (), err )
7095 }
0 commit comments