@@ -11,6 +11,7 @@ import (
1111 "strings"
1212 "sync"
1313
14+ "github.com/go-critic/go-critic/checkers"
1415 gocriticlinter "github.com/go-critic/go-critic/framework/linter"
1516 "golang.org/x/tools/go/analysis"
1617
@@ -28,7 +29,7 @@ func NewGocritic(settings *config.GocriticSettings, cfg *config.Config) *goanaly
2829
2930 sizes := types .SizesFor ("gc" , runtime .GOARCH )
3031
31- wrapper := goCriticWrapper {
32+ wrapper := & goCriticWrapper {
3233 settings : settings ,
3334 cfg : cfg ,
3435 sizes : sizes ,
@@ -71,9 +72,12 @@ type goCriticWrapper struct {
7172 settings * config.GocriticSettings
7273 cfg * config.Config
7374 sizes types.Sizes
75+ once sync.Once
7476}
7577
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+
7781 linterCtx := gocriticlinter .NewContext (pass .Fset , w .sizes )
7882
7983 enabledCheckers , err := w .buildEnabledCheckers (linterCtx )
@@ -93,7 +97,7 @@ func (w goCriticWrapper) run(pass *analysis.Pass) ([]goanalysis.Issue, error) {
9397 return issues , nil
9498}
9599
96- func (w goCriticWrapper ) buildEnabledCheckers (linterCtx * gocriticlinter.Context ) ([]* gocriticlinter.Checker , error ) {
100+ func (w * goCriticWrapper ) buildEnabledCheckers (linterCtx * gocriticlinter.Context ) ([]* gocriticlinter.Checker , error ) {
97101 allParams := w .settings .GetLowercasedParams ()
98102
99103 var enabledCheckers []* gocriticlinter.Checker
@@ -116,23 +120,23 @@ func (w goCriticWrapper) buildEnabledCheckers(linterCtx *gocriticlinter.Context)
116120 return enabledCheckers , nil
117121}
118122
119- func runGocriticOnPackage (linterCtx * gocriticlinter.Context , checkers []* gocriticlinter.Checker ,
123+ func runGocriticOnPackage (linterCtx * gocriticlinter.Context , checks []* gocriticlinter.Checker ,
120124 files []* ast.File ) []result.Issue {
121125 var res []result.Issue
122126 for _ , f := range files {
123127 filename := filepath .Base (linterCtx .FileSet .Position (f .Pos ()).Filename )
124128 linterCtx .SetFileInfo (filename , f )
125129
126- issues := runGocriticOnFile (linterCtx , f , checkers )
130+ issues := runGocriticOnFile (linterCtx , f , checks )
127131 res = append (res , issues ... )
128132 }
129133 return res
130134}
131135
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 {
133137 var res []result.Issue
134138
135- for _ , c := range checkers {
139+ for _ , c := range checks {
136140 // All checkers are expected to use *lint.Context
137141 // as read-only structure, so no copying is required.
138142 for _ , warn := range c .Check (f ) {
@@ -160,7 +164,7 @@ func runGocriticOnFile(linterCtx *gocriticlinter.Context, f *ast.File, checkers
160164 return res
161165}
162166
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 {
164168 params := allParams [strings .ToLower (info .Name )]
165169 if params == nil { // no config for this checker
166170 return nil
@@ -208,7 +212,7 @@ func normalizeCheckerInfoParams(info *gocriticlinter.CheckerInfo) gocriticlinter
208212// but the file parsers (TOML, YAML, JSON) don't create the same representation for raw type.
209213// then we have to convert value types into the expected value types.
210214// 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 {} {
212216 rv := reflect .ValueOf (p )
213217 switch rv .Type ().Kind () {
214218 case reflect .Int64 , reflect .Int32 , reflect .Int16 , reflect .Int8 , reflect .Int :
0 commit comments