Skip to content

Commit b5068cc

Browse files
committed
feat: early validation
1 parent 50fb95e commit b5068cc

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

pkg/commands/linters.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func newLintersCommand(logger logutils.Log) *lintersCommand {
6161
func (c *lintersCommand) preRunE(cmd *cobra.Command, args []string) error {
6262
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
6363

64-
err := loader.Load(config.LoadOptions{})
64+
err := loader.Load(config.LoadOptions{Validation: true})
6565
if err != nil {
6666
return fmt.Errorf("can't load config: %w", err)
6767
}

pkg/commands/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (c *runCommand) persistentPreRunE(cmd *cobra.Command, args []string) error
154154

155155
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
156156

157-
err := loader.Load(config.LoadOptions{CheckDeprecation: true})
157+
err := loader.Load(config.LoadOptions{CheckDeprecation: true, Validation: true})
158158
if err != nil {
159159
return fmt.Errorf("can't load config: %w", err)
160160
}

pkg/config/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ func (c *Config) GetConfigDir() string {
3333

3434
func (c *Config) Validate() error {
3535
validators := []func() error{
36-
c.Issues.Validate,
37-
c.Severity.Validate,
36+
c.Run.Validate,
37+
c.Output.Validate,
3838
c.LintersSettings.Validate,
3939
c.Linters.Validate,
40-
c.Output.Validate,
41-
c.Run.Validate,
40+
c.Issues.Validate,
41+
c.Severity.Validate,
4242
}
4343

4444
for _, v := range validators {

pkg/config/loader.go

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type LoaderOptions struct {
2626

2727
type LoadOptions struct {
2828
CheckDeprecation bool
29+
Validation bool
2930
}
3031

3132
type Loader struct {
@@ -78,6 +79,13 @@ func (l *Loader) Load(opts LoadOptions) error {
7879
return err
7980
}
8081

82+
if opts.Validation {
83+
err = l.cfg.Validate()
84+
if err != nil {
85+
return err
86+
}
87+
}
88+
8189
return nil
8290
}
8391

pkg/lint/lintersdb/validator.go

-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ func NewValidator(m *Manager) *Validator {
2222
// Validate validates the configuration by calling all other validators for different
2323
// sections in the configuration and then some additional linter validation functions.
2424
func (v Validator) Validate(cfg *config.Config) error {
25-
err := cfg.Validate()
26-
if err != nil {
27-
return err
28-
}
29-
3025
validators := []func(cfg *config.Linters) error{
3126
v.validateLintersNames,
3227
v.validatePresets,

0 commit comments

Comments
 (0)