Skip to content

Commit

Permalink
fix: refactor the configuration loading and parsing system
Browse files Browse the repository at this point in the history
It's only a first step, must be rewrite in the future.
  • Loading branch information
ldez committed Aug 14, 2022
1 parent 1f10e86 commit 29cc1d9
Show file tree
Hide file tree
Showing 9 changed files with 457 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .golangci.reference.yml
Expand Up @@ -1113,7 +1113,7 @@ linters-settings:
makezero:
# Allow only slices initialized with a length of zero.
# Default: false
always: false
always: true

maligned:
# Print struct with more effective memory layout or not.
Expand Down
5 changes: 0 additions & 5 deletions pkg/commands/executor.go
Expand Up @@ -117,11 +117,6 @@ func NewExecutor(version, commit, date string) *Executor {
// recreate after getting config
e.DBManager = lintersdb.NewManager(e.cfg, e.log).WithCustomLinters()

e.cfg.LintersSettings.Gocritic.InferEnabledChecks(e.log)
if err = e.cfg.LintersSettings.Gocritic.Validate(e.log); err != nil {
e.log.Fatalf("Invalid gocritic settings: %s", err)
}

// Slice options must be explicitly set for proper merging of config and command-line options.
fixSlicesFlags(e.runCmd.Flags())
fixSlicesFlags(e.lintersCmd.Flags())
Expand Down
16 changes: 13 additions & 3 deletions pkg/config/linters_settings.go
Expand Up @@ -40,8 +40,8 @@ var defaultLintersSettings = LintersSettings{
Gocognit: GocognitSettings{
MinComplexity: 30,
},
Gocritic: GocriticSettings{
SettingsPerCheck: map[string]GocriticCheckSettings{},
Gocritic: GoCriticSettings{
SettingsPerCheck: map[string]GoCriticCheckSettings{},
},
Godox: GodoxSettings{
Keywords: []string{},
Expand Down Expand Up @@ -133,7 +133,7 @@ type LintersSettings struct {
Gci GciSettings
Gocognit GocognitSettings
Goconst GoConstSettings
Gocritic GocriticSettings
Gocritic GoCriticSettings
Gocyclo GoCycloSettings
Godot GodotSettings
Godox GodoxSettings
Expand Down Expand Up @@ -306,6 +306,16 @@ type GoConstSettings struct {
IgnoreCalls bool `mapstructure:"ignore-calls"`
}

type GoCriticSettings struct {
EnabledChecks []string `mapstructure:"enabled-checks"`
DisabledChecks []string `mapstructure:"disabled-checks"`
EnabledTags []string `mapstructure:"enabled-tags"`
DisabledTags []string `mapstructure:"disabled-tags"`
SettingsPerCheck map[string]GoCriticCheckSettings `mapstructure:"settings"`
}

type GoCriticCheckSettings map[string]interface{}

type GoCycloSettings struct {
MinComplexity int `mapstructure:"min-complexity"`
}
Expand Down

0 comments on commit 29cc1d9

Please sign in to comment.