@@ -11,6 +11,7 @@ import (
11
11
"strings"
12
12
"sync"
13
13
14
+ "github.com/go-critic/go-critic/checkers"
14
15
gocriticlinter "github.com/go-critic/go-critic/framework/linter"
15
16
"golang.org/x/tools/go/analysis"
16
17
@@ -28,7 +29,7 @@ func NewGocritic(settings *config.GocriticSettings, cfg *config.Config) *goanaly
28
29
29
30
sizes := types .SizesFor ("gc" , runtime .GOARCH )
30
31
31
- wrapper := goCriticWrapper {
32
+ wrapper := & goCriticWrapper {
32
33
settings : settings ,
33
34
cfg : cfg ,
34
35
sizes : sizes ,
@@ -71,9 +72,12 @@ type goCriticWrapper struct {
71
72
settings * config.GocriticSettings
72
73
cfg * config.Config
73
74
sizes types.Sizes
75
+ once sync.Once
74
76
}
75
77
76
- func (w goCriticWrapper ) run (pass * analysis.Pass ) ([]goanalysis.Issue , error ) {
78
+ func (w * goCriticWrapper ) run (pass * analysis.Pass ) ([]goanalysis.Issue , error ) {
79
+ w .once .Do (checkers .InitEmbeddedRules )
80
+
77
81
linterCtx := gocriticlinter .NewContext (pass .Fset , w .sizes )
78
82
79
83
enabledCheckers , err := w .buildEnabledCheckers (linterCtx )
@@ -93,7 +97,7 @@ func (w goCriticWrapper) run(pass *analysis.Pass) ([]goanalysis.Issue, error) {
93
97
return issues , nil
94
98
}
95
99
96
- func (w goCriticWrapper ) buildEnabledCheckers (linterCtx * gocriticlinter.Context ) ([]* gocriticlinter.Checker , error ) {
100
+ func (w * goCriticWrapper ) buildEnabledCheckers (linterCtx * gocriticlinter.Context ) ([]* gocriticlinter.Checker , error ) {
97
101
allParams := w .settings .GetLowercasedParams ()
98
102
99
103
var enabledCheckers []* gocriticlinter.Checker
@@ -116,23 +120,23 @@ func (w goCriticWrapper) buildEnabledCheckers(linterCtx *gocriticlinter.Context)
116
120
return enabledCheckers , nil
117
121
}
118
122
119
- func runGocriticOnPackage (linterCtx * gocriticlinter.Context , checkers []* gocriticlinter.Checker ,
123
+ func runGocriticOnPackage (linterCtx * gocriticlinter.Context , checks []* gocriticlinter.Checker ,
120
124
files []* ast.File ) []result.Issue {
121
125
var res []result.Issue
122
126
for _ , f := range files {
123
127
filename := filepath .Base (linterCtx .FileSet .Position (f .Pos ()).Filename )
124
128
linterCtx .SetFileInfo (filename , f )
125
129
126
- issues := runGocriticOnFile (linterCtx , f , checkers )
130
+ issues := runGocriticOnFile (linterCtx , f , checks )
127
131
res = append (res , issues ... )
128
132
}
129
133
return res
130
134
}
131
135
132
- func runGocriticOnFile (linterCtx * gocriticlinter.Context , f * ast.File , checkers []* gocriticlinter.Checker ) []result.Issue {
136
+ func runGocriticOnFile (linterCtx * gocriticlinter.Context , f * ast.File , checks []* gocriticlinter.Checker ) []result.Issue {
133
137
var res []result.Issue
134
138
135
- for _ , c := range checkers {
139
+ for _ , c := range checks {
136
140
// All checkers are expected to use *lint.Context
137
141
// as read-only structure, so no copying is required.
138
142
for _ , warn := range c .Check (f ) {
@@ -160,7 +164,7 @@ func runGocriticOnFile(linterCtx *gocriticlinter.Context, f *ast.File, checkers
160
164
return res
161
165
}
162
166
163
- func (w goCriticWrapper ) configureCheckerInfo (info * gocriticlinter.CheckerInfo , allParams map [string ]config.GocriticCheckSettings ) error {
167
+ func (w * goCriticWrapper ) configureCheckerInfo (info * gocriticlinter.CheckerInfo , allParams map [string ]config.GocriticCheckSettings ) error {
164
168
params := allParams [strings .ToLower (info .Name )]
165
169
if params == nil { // no config for this checker
166
170
return nil
@@ -208,7 +212,7 @@ func normalizeCheckerInfoParams(info *gocriticlinter.CheckerInfo) gocriticlinter
208
212
// but the file parsers (TOML, YAML, JSON) don't create the same representation for raw type.
209
213
// then we have to convert value types into the expected value types.
210
214
// Maybe in the future, this kind of conversion will be done in go-critic itself.
211
- func (w goCriticWrapper ) normalizeCheckerParamsValue (p interface {}) interface {} {
215
+ func (w * goCriticWrapper ) normalizeCheckerParamsValue (p interface {}) interface {} {
212
216
rv := reflect .ValueOf (p )
213
217
switch rv .Type ().Kind () {
214
218
case reflect .Int64 , reflect .Int32 , reflect .Int16 , reflect .Int8 , reflect .Int :
0 commit comments