@@ -10,6 +10,7 @@ import (
10
10
"github.com/golangci/golangci-lint/pkg/config"
11
11
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
12
12
"github.com/golangci/golangci-lint/pkg/lint/linter"
13
+ "github.com/golangci/golangci-lint/pkg/logutils"
13
14
"github.com/golangci/golangci-lint/pkg/result"
14
15
)
15
16
@@ -40,6 +41,9 @@ func NewForbidigo(settings *config.ForbidigoSettings) *goanalysis.Linter {
40
41
},
41
42
}
42
43
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.
43
47
return goanalysis .NewLinter (
44
48
forbidigoName ,
45
49
"Forbids identifiers" ,
@@ -55,16 +59,34 @@ func runForbidigo(pass *analysis.Pass, settings *config.ForbidigoSettings) ([]go
55
59
forbidigo .OptionExcludeGodocExamples (settings .ExcludeGodocExamples ),
56
60
// disable "//permit" directives so only "//nolint" directives matters within golangci-lint
57
61
forbidigo .OptionIgnorePermitDirectives (true ),
62
+ forbidigo .OptionAnalyzeTypes (settings .AnalyzeTypes ),
58
63
}
59
64
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 ... )
61
76
if err != nil {
62
77
return nil , fmt .Errorf ("failed to create linter %q: %w" , forbidigoName , err )
63
78
}
64
79
65
80
var issues []goanalysis.Issue
66
81
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 )
68
90
if err != nil {
69
91
return nil , fmt .Errorf ("forbidigo linter failed on file %q: %w" , file .Name .String (), err )
70
92
}
0 commit comments