@@ -24,6 +24,11 @@ type LoaderOptions struct {
2424 NoConfig bool // Flag only.
2525}
2626
27+ type LoadOptions struct {
28+ CheckDeprecation bool
29+ Validation bool
30+ }
31+
2732type Loader struct {
2833 opts LoaderOptions
2934
@@ -47,7 +52,7 @@ func NewLoader(log logutils.Log, v *viper.Viper, fs *pflag.FlagSet, opts LoaderO
4752 }
4853}
4954
50- func (l * Loader ) Load () error {
55+ func (l * Loader ) Load (opts LoadOptions ) error {
5156 err := l .setConfigFile ()
5257 if err != nil {
5358 return err
@@ -60,9 +65,11 @@ func (l *Loader) Load() error {
6065
6166 l .applyStringSliceHack ()
6267
63- err = l .handleDeprecation ()
64- if err != nil {
65- return err
68+ if opts .CheckDeprecation {
69+ err = l .handleDeprecation ()
70+ if err != nil {
71+ return err
72+ }
6673 }
6774
6875 l .handleGoVersion ()
@@ -72,6 +79,13 @@ func (l *Loader) Load() error {
7279 return err
7380 }
7481
82+ if opts .Validation {
83+ err = l .cfg .Validate ()
84+ if err != nil {
85+ return err
86+ }
87+ }
88+
7589 return nil
7690}
7791
@@ -293,35 +307,39 @@ func (l *Loader) handleGoVersion() {
293307}
294308
295309func (l * Loader ) handleDeprecation () error {
310+ if l .cfg .InternalTest || l .cfg .InternalCmdTest || os .Getenv (logutils .EnvTestRun ) == "1" {
311+ return nil
312+ }
313+
296314 // Deprecated since v1.57.0
297315 if len (l .cfg .Run .SkipFiles ) > 0 {
298- l .warn ("The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`." )
316+ l .log . Warnf ("The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`." )
299317 l .cfg .Issues .ExcludeFiles = l .cfg .Run .SkipFiles
300318 }
301319
302320 // Deprecated since v1.57.0
303321 if len (l .cfg .Run .SkipDirs ) > 0 {
304- l .warn ("The configuration option `run.skip-dirs` is deprecated, please use `issues.exclude-dirs`." )
322+ l .log . Warnf ("The configuration option `run.skip-dirs` is deprecated, please use `issues.exclude-dirs`." )
305323 l .cfg .Issues .ExcludeDirs = l .cfg .Run .SkipDirs
306324 }
307325
308326 // The 2 options are true by default.
309327 // Deprecated since v1.57.0
310328 if ! l .cfg .Run .UseDefaultSkipDirs {
311- l .warn ("The configuration option `run.skip-dirs-use-default` is deprecated, please use `issues.exclude-dirs-use-default`." )
329+ l .log . Warnf ("The configuration option `run.skip-dirs-use-default` is deprecated, please use `issues.exclude-dirs-use-default`." )
312330 }
313331 l .cfg .Issues .UseDefaultExcludeDirs = l .cfg .Run .UseDefaultSkipDirs && l .cfg .Issues .UseDefaultExcludeDirs
314332
315333 // The 2 options are false by default.
316334 // Deprecated since v1.57.0
317335 if l .cfg .Run .ShowStats {
318- l .warn ("The configuration option `run.show-stats` is deprecated, please use `output.show-stats`" )
336+ l .log . Warnf ("The configuration option `run.show-stats` is deprecated, please use `output.show-stats`" )
319337 }
320338 l .cfg .Output .ShowStats = l .cfg .Run .ShowStats || l .cfg .Output .ShowStats
321339
322340 // Deprecated since v1.57.0
323341 if l .cfg .Output .Format != "" {
324- l .warn ("The configuration option `output.format` is deprecated, please use `output.formats`" )
342+ l .log . Warnf ("The configuration option `output.format` is deprecated, please use `output.formats`" )
325343
326344 var f OutputFormats
327345 err := f .UnmarshalText ([]byte (l .cfg .Output .Format ))
@@ -341,49 +359,49 @@ func (l *Loader) handleLinterOptionDeprecations() {
341359 // Deprecated since v1.57.0,
342360 // but it was unofficially deprecated since v1.19 (2019) (https://github.com/golangci/golangci-lint/pull/697).
343361 if l .cfg .LintersSettings .Govet .CheckShadowing {
344- l .warn ("The configuration option `linters.govet.check-shadowing` is deprecated. " +
362+ l .log . Warnf ("The configuration option `linters.govet.check-shadowing` is deprecated. " +
345363 "Please enable `shadow` instead, if you are not using `enable-all`." )
346364 }
347365
348366 // Deprecated since v1.42.0.
349367 if l .cfg .LintersSettings .Errcheck .Exclude != "" {
350- l .warn ("The configuration option `linters.errcheck.exclude` is deprecated, please use `linters.errcheck.exclude-functions`." )
368+ l .log . Warnf ("The configuration option `linters.errcheck.exclude` is deprecated, please use `linters.errcheck.exclude-functions`." )
351369 }
352370
353371 // Deprecated since v1.44.0.
354372 if l .cfg .LintersSettings .Gci .LocalPrefixes != "" {
355- l .warn ("The configuration option `linters.gci.local-prefixes` is deprecated, please use `prefix()` inside `linters.gci.sections`." )
373+ l .log . Warnf ("The configuration option `linters.gci.local-prefixes` is deprecated, please use `prefix()` inside `linters.gci.sections`." )
356374 }
357375
358376 // Deprecated since v1.33.0.
359377 if l .cfg .LintersSettings .Godot .CheckAll {
360- l .warn ("The configuration option `linters.godot.check-all` is deprecated, please use `linters.godot.scope: all`." )
378+ l .log . Warnf ("The configuration option `linters.godot.check-all` is deprecated, please use `linters.godot.scope: all`." )
361379 }
362380
363381 // Deprecated since v1.44.0.
364382 if len (l .cfg .LintersSettings .Gomnd .Settings ) > 0 {
365- l .warn ("The configuration option `linters.gomnd.settings` is deprecated. Please use the options " +
383+ l .log . Warnf ("The configuration option `linters.gomnd.settings` is deprecated. Please use the options " +
366384 "`linters.gomnd.checks`,`linters.gomnd.ignored-numbers`,`linters.gomnd.ignored-files`,`linters.gomnd.ignored-functions`." )
367385 }
368386
369387 // Deprecated since v1.47.0
370388 if l .cfg .LintersSettings .Gofumpt .LangVersion != "" {
371- l .warn ("The configuration option `linters.gofumpt.lang-version` is deprecated, please use global `run.go`." )
389+ l .log . Warnf ("The configuration option `linters.gofumpt.lang-version` is deprecated, please use global `run.go`." )
372390 }
373391
374392 // Deprecated since v1.47.0
375393 if l .cfg .LintersSettings .Staticcheck .GoVersion != "" {
376- l .warn ("The configuration option `linters.staticcheck.go` is deprecated, please use global `run.go`." )
394+ l .log . Warnf ("The configuration option `linters.staticcheck.go` is deprecated, please use global `run.go`." )
377395 }
378396
379397 // Deprecated since v1.47.0
380398 if l .cfg .LintersSettings .Gosimple .GoVersion != "" {
381- l .warn ("The configuration option `linters.gosimple.go` is deprecated, please use global `run.go`." )
399+ l .log . Warnf ("The configuration option `linters.gosimple.go` is deprecated, please use global `run.go`." )
382400 }
383401
384402 // Deprecated since v1.47.0
385403 if l .cfg .LintersSettings .Stylecheck .GoVersion != "" {
386- l .warn ("The configuration option `linters.stylecheck.go` is deprecated, please use global `run.go`." )
404+ l .log . Warnf ("The configuration option `linters.stylecheck.go` is deprecated, please use global `run.go`." )
387405 }
388406}
389407
@@ -408,14 +426,6 @@ func (l *Loader) handleEnableOnlyOption() error {
408426 return nil
409427}
410428
411- func (l * Loader ) warn (format string ) {
412- if l .cfg .InternalTest || l .cfg .InternalCmdTest || os .Getenv (logutils .EnvTestRun ) == "1" {
413- return
414- }
415-
416- l .log .Warnf (format )
417- }
418-
419429func customDecoderHook () viper.DecoderConfigOption {
420430 return viper .DecodeHook (mapstructure .ComposeDecodeHookFunc (
421431 // Default hooks (https://github.com/spf13/viper/blob/518241257478c557633ab36e474dfcaeb9a3c623/viper.go#L135-L138).
0 commit comments