@@ -24,6 +24,10 @@ type LoaderOptions struct {
2424 NoConfig bool // Flag only.
2525}
2626
27+ type LoadOptions struct {
28+ CheckDeprecation bool
29+ }
30+
2731type Loader struct {
2832 opts LoaderOptions
2933
@@ -47,7 +51,7 @@ func NewLoader(log logutils.Log, v *viper.Viper, fs *pflag.FlagSet, opts LoaderO
4751 }
4852}
4953
50- func (l * Loader ) Load () error {
54+ func (l * Loader ) Load (opts LoadOptions ) error {
5155 err := l .setConfigFile ()
5256 if err != nil {
5357 return err
@@ -60,9 +64,11 @@ func (l *Loader) Load() error {
6064
6165 l .applyStringSliceHack ()
6266
63- err = l .handleDeprecation ()
64- if err != nil {
65- return err
67+ if opts .CheckDeprecation {
68+ err = l .handleDeprecation ()
69+ if err != nil {
70+ return err
71+ }
6672 }
6773
6874 l .handleGoVersion ()
@@ -293,35 +299,39 @@ func (l *Loader) handleGoVersion() {
293299}
294300
295301func (l * Loader ) handleDeprecation () error {
302+ if l .cfg .InternalTest || l .cfg .InternalCmdTest || os .Getenv (logutils .EnvTestRun ) == "1" {
303+ return nil
304+ }
305+
296306 // Deprecated since v1.57.0
297307 if len (l .cfg .Run .SkipFiles ) > 0 {
298- l .warn ("The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`." )
308+ l .log . Warnf ("The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`." )
299309 l .cfg .Issues .ExcludeFiles = l .cfg .Run .SkipFiles
300310 }
301311
302312 // Deprecated since v1.57.0
303313 if len (l .cfg .Run .SkipDirs ) > 0 {
304- l .warn ("The configuration option `run.skip-dirs` is deprecated, please use `issues.exclude-dirs`." )
314+ l .log . Warnf ("The configuration option `run.skip-dirs` is deprecated, please use `issues.exclude-dirs`." )
305315 l .cfg .Issues .ExcludeDirs = l .cfg .Run .SkipDirs
306316 }
307317
308318 // The 2 options are true by default.
309319 // Deprecated since v1.57.0
310320 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`." )
321+ l .log . Warnf ("The configuration option `run.skip-dirs-use-default` is deprecated, please use `issues.exclude-dirs-use-default`." )
312322 }
313323 l .cfg .Issues .UseDefaultExcludeDirs = l .cfg .Run .UseDefaultSkipDirs && l .cfg .Issues .UseDefaultExcludeDirs
314324
315325 // The 2 options are false by default.
316326 // Deprecated since v1.57.0
317327 if l .cfg .Run .ShowStats {
318- l .warn ("The configuration option `run.show-stats` is deprecated, please use `output.show-stats`" )
328+ l .log . Warnf ("The configuration option `run.show-stats` is deprecated, please use `output.show-stats`" )
319329 }
320330 l .cfg .Output .ShowStats = l .cfg .Run .ShowStats || l .cfg .Output .ShowStats
321331
322332 // Deprecated since v1.57.0
323333 if l .cfg .Output .Format != "" {
324- l .warn ("The configuration option `output.format` is deprecated, please use `output.formats`" )
334+ l .log . Warnf ("The configuration option `output.format` is deprecated, please use `output.formats`" )
325335
326336 var f OutputFormats
327337 err := f .UnmarshalText ([]byte (l .cfg .Output .Format ))
@@ -341,49 +351,49 @@ func (l *Loader) handleLinterOptionDeprecations() {
341351 // Deprecated since v1.57.0,
342352 // but it was unofficially deprecated since v1.19 (2019) (https://github.com/golangci/golangci-lint/pull/697).
343353 if l .cfg .LintersSettings .Govet .CheckShadowing {
344- l .warn ("The configuration option `linters.govet.check-shadowing` is deprecated. " +
354+ l .log . Warnf ("The configuration option `linters.govet.check-shadowing` is deprecated. " +
345355 "Please enable `shadow` instead, if you are not using `enable-all`." )
346356 }
347357
348358 // Deprecated since v1.42.0.
349359 if l .cfg .LintersSettings .Errcheck .Exclude != "" {
350- l .warn ("The configuration option `linters.errcheck.exclude` is deprecated, please use `linters.errcheck.exclude-functions`." )
360+ l .log . Warnf ("The configuration option `linters.errcheck.exclude` is deprecated, please use `linters.errcheck.exclude-functions`." )
351361 }
352362
353363 // Deprecated since v1.44.0.
354364 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`." )
365+ l .log . Warnf ("The configuration option `linters.gci.local-prefixes` is deprecated, please use `prefix()` inside `linters.gci.sections`." )
356366 }
357367
358368 // Deprecated since v1.33.0.
359369 if l .cfg .LintersSettings .Godot .CheckAll {
360- l .warn ("The configuration option `linters.godot.check-all` is deprecated, please use `linters.godot.scope: all`." )
370+ l .log . Warnf ("The configuration option `linters.godot.check-all` is deprecated, please use `linters.godot.scope: all`." )
361371 }
362372
363373 // Deprecated since v1.44.0.
364374 if len (l .cfg .LintersSettings .Gomnd .Settings ) > 0 {
365- l .warn ("The configuration option `linters.gomnd.settings` is deprecated. Please use the options " +
375+ l .log . Warnf ("The configuration option `linters.gomnd.settings` is deprecated. Please use the options " +
366376 "`linters.gomnd.checks`,`linters.gomnd.ignored-numbers`,`linters.gomnd.ignored-files`,`linters.gomnd.ignored-functions`." )
367377 }
368378
369379 // Deprecated since v1.47.0
370380 if l .cfg .LintersSettings .Gofumpt .LangVersion != "" {
371- l .warn ("The configuration option `linters.gofumpt.lang-version` is deprecated, please use global `run.go`." )
381+ l .log . Warnf ("The configuration option `linters.gofumpt.lang-version` is deprecated, please use global `run.go`." )
372382 }
373383
374384 // Deprecated since v1.47.0
375385 if l .cfg .LintersSettings .Staticcheck .GoVersion != "" {
376- l .warn ("The configuration option `linters.staticcheck.go` is deprecated, please use global `run.go`." )
386+ l .log . Warnf ("The configuration option `linters.staticcheck.go` is deprecated, please use global `run.go`." )
377387 }
378388
379389 // Deprecated since v1.47.0
380390 if l .cfg .LintersSettings .Gosimple .GoVersion != "" {
381- l .warn ("The configuration option `linters.gosimple.go` is deprecated, please use global `run.go`." )
391+ l .log . Warnf ("The configuration option `linters.gosimple.go` is deprecated, please use global `run.go`." )
382392 }
383393
384394 // Deprecated since v1.47.0
385395 if l .cfg .LintersSettings .Stylecheck .GoVersion != "" {
386- l .warn ("The configuration option `linters.stylecheck.go` is deprecated, please use global `run.go`." )
396+ l .log . Warnf ("The configuration option `linters.stylecheck.go` is deprecated, please use global `run.go`." )
387397 }
388398}
389399
@@ -408,14 +418,6 @@ func (l *Loader) handleEnableOnlyOption() error {
408418 return nil
409419}
410420
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-
419421func customDecoderHook () viper.DecoderConfigOption {
420422 return viper .DecodeHook (mapstructure .ComposeDecodeHookFunc (
421423 // Default hooks (https://github.com/spf13/viper/blob/518241257478c557633ab36e474dfcaeb9a3c623/viper.go#L135-L138).
0 commit comments