@@ -10,12 +10,12 @@ 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
16
17
const forbidigoName = "forbidigo"
17
18
18
- //nolint:dupl
19
19
func NewForbidigo (settings * config.ForbidigoSettings ) * goanalysis.Linter {
20
20
var mu sync.Mutex
21
21
var resIssues []goanalysis.Issue
@@ -40,14 +40,20 @@ func NewForbidigo(settings *config.ForbidigoSettings) *goanalysis.Linter {
40
40
},
41
41
}
42
42
43
+ loadMode := goanalysis .LoadModeSyntax
44
+ if settings != nil && settings .AnalyzeTypes {
45
+ // Need more information for the analysis.
46
+ loadMode = goanalysis .LoadModeTypesInfo
47
+ }
48
+
43
49
return goanalysis .NewLinter (
44
50
forbidigoName ,
45
51
"Forbids identifiers" ,
46
52
[]* analysis.Analyzer {analyzer },
47
53
nil ,
48
54
).WithIssuesReporter (func (* linter.Context ) []goanalysis.Issue {
49
55
return resIssues
50
- }).WithLoadMode (goanalysis . LoadModeSyntax )
56
+ }).WithLoadMode (loadMode )
51
57
}
52
58
53
59
func runForbidigo (pass * analysis.Pass , settings * config.ForbidigoSettings ) ([]goanalysis.Issue , error ) {
@@ -57,14 +63,32 @@ func runForbidigo(pass *analysis.Pass, settings *config.ForbidigoSettings) ([]go
57
63
forbidigo .OptionIgnorePermitDirectives (true ),
58
64
}
59
65
60
- forbid , err := forbidigo .NewLinter (settings .Forbid , options ... )
66
+ // Convert patterns back to strings because that is what NewLinter
67
+ // accepts.
68
+ var patterns []string
69
+ for _ , pattern := range settings .Forbid {
70
+ buffer , err := pattern .String ()
71
+ if err != nil {
72
+ return nil , err
73
+ }
74
+ patterns = append (patterns , string (buffer ))
75
+ }
76
+
77
+ forbid , err := forbidigo .NewLinter (patterns , options ... )
61
78
if err != nil {
62
79
return nil , errors .Wrapf (err , "failed to create linter %q" , forbidigoName )
63
80
}
64
81
65
82
var issues []goanalysis.Issue
66
83
for _ , file := range pass .Files {
67
- hints , err := forbid .RunWithConfig (forbidigo.RunConfig {Fset : pass .Fset }, file )
84
+ runConfig := forbidigo.RunConfig {
85
+ Fset : pass .Fset ,
86
+ DebugLog : logutils .Debug (logutils .DebugKeyForbidigo ),
87
+ }
88
+ if settings != nil && settings .AnalyzeTypes {
89
+ runConfig .TypesInfo = pass .TypesInfo
90
+ }
91
+ hints , err := forbid .RunWithConfig (runConfig , file )
68
92
if err != nil {
69
93
return nil , errors .Wrapf (err , "forbidigo linter failed on file %q" , file .Name .String ())
70
94
}
0 commit comments