Skip to content

Commit 013a296

Browse files
authored
dev: review config path usage inside gocritic (#4517)
1 parent 39617e4 commit 013a296

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pkg/golinters/gocritic.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ var (
3232
isGoCriticDebug = logutils.HaveDebugTag(logutils.DebugKeyGoCritic)
3333
)
3434

35-
func NewGoCritic(settings *config.GoCriticSettings, cfg *config.Config) *goanalysis.Linter {
35+
func NewGoCritic(settings *config.GoCriticSettings) *goanalysis.Linter {
3636
var mu sync.Mutex
3737
var resIssues []goanalysis.Issue
3838

3939
wrapper := &goCriticWrapper{
40-
getConfigDir: cfg.GetConfigDir, // Config directory is filled after calling this constructor.
41-
sizes: types.SizesFor("gc", runtime.GOARCH),
40+
sizes: types.SizesFor("gc", runtime.GOARCH),
4241
}
4342

4443
analyzer := &analysis.Analyzer{
@@ -71,7 +70,9 @@ Dynamic rules are written declaratively with AST patterns, filters, report messa
7170
nil,
7271
).
7372
WithContextSetter(func(context *linter.Context) {
74-
wrapper.init(settings, context.Log)
73+
wrapper.configDir = context.Cfg.GetConfigDir()
74+
75+
wrapper.init(context.Log, settings)
7576
}).
7677
WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
7778
return resIssues
@@ -81,12 +82,12 @@ Dynamic rules are written declaratively with AST patterns, filters, report messa
8182

8283
type goCriticWrapper struct {
8384
settingsWrapper *goCriticSettingsWrapper
84-
getConfigDir func() string
85+
configDir string
8586
sizes types.Sizes
8687
once sync.Once
8788
}
8889

89-
func (w *goCriticWrapper) init(settings *config.GoCriticSettings, logger logutils.Log) {
90+
func (w *goCriticWrapper) init(logger logutils.Log, settings *config.GoCriticSettings) {
9091
if settings == nil {
9192
return
9293
}
@@ -206,7 +207,7 @@ func (w *goCriticWrapper) normalizeCheckerParamsValue(p any) any {
206207
return rv.Bool()
207208
case reflect.String:
208209
// Perform variable substitution.
209-
return strings.ReplaceAll(rv.String(), "${configDir}", w.getConfigDir())
210+
return strings.ReplaceAll(rv.String(), "${configDir}", w.configDir)
210211
default:
211212
return p
212213
}

pkg/lint/lintersdb/builder_linter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (b LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
228228
WithPresets(linter.PresetStyle).
229229
WithURL("https://github.com/jgautheron/goconst"),
230230

231-
linter.NewConfig(golinters.NewGoCritic(&cfg.LintersSettings.Gocritic, cfg)).
231+
linter.NewConfig(golinters.NewGoCritic(&cfg.LintersSettings.Gocritic)).
232232
WithSince("v1.12.0").
233233
WithPresets(linter.PresetStyle, linter.PresetMetaLinter).
234234
WithLoadForGoAnalysis().

0 commit comments

Comments
 (0)