dev: review config path usage inside gocritic (#4517)
This commit is contained in:
parent
39617e4db3
commit
013a296577
@ -32,12 +32,11 @@ var (
|
|||||||
isGoCriticDebug = logutils.HaveDebugTag(logutils.DebugKeyGoCritic)
|
isGoCriticDebug = logutils.HaveDebugTag(logutils.DebugKeyGoCritic)
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewGoCritic(settings *config.GoCriticSettings, cfg *config.Config) *goanalysis.Linter {
|
func NewGoCritic(settings *config.GoCriticSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
|
||||||
wrapper := &goCriticWrapper{
|
wrapper := &goCriticWrapper{
|
||||||
getConfigDir: cfg.GetConfigDir, // Config directory is filled after calling this constructor.
|
|
||||||
sizes: types.SizesFor("gc", runtime.GOARCH),
|
sizes: types.SizesFor("gc", runtime.GOARCH),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +70,9 @@ Dynamic rules are written declaratively with AST patterns, filters, report messa
|
|||||||
nil,
|
nil,
|
||||||
).
|
).
|
||||||
WithContextSetter(func(context *linter.Context) {
|
WithContextSetter(func(context *linter.Context) {
|
||||||
wrapper.init(settings, context.Log)
|
wrapper.configDir = context.Cfg.GetConfigDir()
|
||||||
|
|
||||||
|
wrapper.init(context.Log, settings)
|
||||||
}).
|
}).
|
||||||
WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
|
WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
|
||||||
return resIssues
|
return resIssues
|
||||||
@ -81,12 +82,12 @@ Dynamic rules are written declaratively with AST patterns, filters, report messa
|
|||||||
|
|
||||||
type goCriticWrapper struct {
|
type goCriticWrapper struct {
|
||||||
settingsWrapper *goCriticSettingsWrapper
|
settingsWrapper *goCriticSettingsWrapper
|
||||||
getConfigDir func() string
|
configDir string
|
||||||
sizes types.Sizes
|
sizes types.Sizes
|
||||||
once sync.Once
|
once sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *goCriticWrapper) init(settings *config.GoCriticSettings, logger logutils.Log) {
|
func (w *goCriticWrapper) init(logger logutils.Log, settings *config.GoCriticSettings) {
|
||||||
if settings == nil {
|
if settings == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -206,7 +207,7 @@ func (w *goCriticWrapper) normalizeCheckerParamsValue(p any) any {
|
|||||||
return rv.Bool()
|
return rv.Bool()
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
// Perform variable substitution.
|
// Perform variable substitution.
|
||||||
return strings.ReplaceAll(rv.String(), "${configDir}", w.getConfigDir())
|
return strings.ReplaceAll(rv.String(), "${configDir}", w.configDir)
|
||||||
default:
|
default:
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ func (b LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
|
|||||||
WithPresets(linter.PresetStyle).
|
WithPresets(linter.PresetStyle).
|
||||||
WithURL("https://github.com/jgautheron/goconst"),
|
WithURL("https://github.com/jgautheron/goconst"),
|
||||||
|
|
||||||
linter.NewConfig(golinters.NewGoCritic(&cfg.LintersSettings.Gocritic, cfg)).
|
linter.NewConfig(golinters.NewGoCritic(&cfg.LintersSettings.Gocritic)).
|
||||||
WithSince("v1.12.0").
|
WithSince("v1.12.0").
|
||||||
WithPresets(linter.PresetStyle, linter.PresetMetaLinter).
|
WithPresets(linter.PresetStyle, linter.PresetMetaLinter).
|
||||||
WithLoadForGoAnalysis().
|
WithLoadForGoAnalysis().
|
||||||
|
Loading…
x
Reference in New Issue
Block a user