@@ -24,6 +24,10 @@ type LoaderOptions struct {
24
24
NoConfig bool // Flag only.
25
25
}
26
26
27
+ type LoadOptions struct {
28
+ CheckDeprecation bool
29
+ }
30
+
27
31
type Loader struct {
28
32
opts LoaderOptions
29
33
@@ -47,7 +51,7 @@ func NewLoader(log logutils.Log, v *viper.Viper, fs *pflag.FlagSet, opts LoaderO
47
51
}
48
52
}
49
53
50
- func (l * Loader ) Load () error {
54
+ func (l * Loader ) Load (opts LoadOptions ) error {
51
55
err := l .setConfigFile ()
52
56
if err != nil {
53
57
return err
@@ -60,9 +64,11 @@ func (l *Loader) Load() error {
60
64
61
65
l .applyStringSliceHack ()
62
66
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
+ }
66
72
}
67
73
68
74
l .handleGoVersion ()
@@ -293,35 +299,39 @@ func (l *Loader) handleGoVersion() {
293
299
}
294
300
295
301
func (l * Loader ) handleDeprecation () error {
302
+ if l .cfg .InternalTest || l .cfg .InternalCmdTest || os .Getenv (logutils .EnvTestRun ) == "1" {
303
+ return nil
304
+ }
305
+
296
306
// Deprecated since v1.57.0
297
307
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`." )
299
309
l .cfg .Issues .ExcludeFiles = l .cfg .Run .SkipFiles
300
310
}
301
311
302
312
// Deprecated since v1.57.0
303
313
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`." )
305
315
l .cfg .Issues .ExcludeDirs = l .cfg .Run .SkipDirs
306
316
}
307
317
308
318
// The 2 options are true by default.
309
319
// Deprecated since v1.57.0
310
320
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`." )
312
322
}
313
323
l .cfg .Issues .UseDefaultExcludeDirs = l .cfg .Run .UseDefaultSkipDirs && l .cfg .Issues .UseDefaultExcludeDirs
314
324
315
325
// The 2 options are false by default.
316
326
// Deprecated since v1.57.0
317
327
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`" )
319
329
}
320
330
l .cfg .Output .ShowStats = l .cfg .Run .ShowStats || l .cfg .Output .ShowStats
321
331
322
332
// Deprecated since v1.57.0
323
333
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`" )
325
335
326
336
var f OutputFormats
327
337
err := f .UnmarshalText ([]byte (l .cfg .Output .Format ))
@@ -341,49 +351,49 @@ func (l *Loader) handleLinterOptionDeprecations() {
341
351
// Deprecated since v1.57.0,
342
352
// but it was unofficially deprecated since v1.19 (2019) (https://github.com/golangci/golangci-lint/pull/697).
343
353
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. " +
345
355
"Please enable `shadow` instead, if you are not using `enable-all`." )
346
356
}
347
357
348
358
// Deprecated since v1.42.0.
349
359
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`." )
351
361
}
352
362
353
363
// Deprecated since v1.44.0.
354
364
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`." )
356
366
}
357
367
358
368
// Deprecated since v1.33.0.
359
369
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`." )
361
371
}
362
372
363
373
// Deprecated since v1.44.0.
364
374
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 " +
366
376
"`linters.gomnd.checks`,`linters.gomnd.ignored-numbers`,`linters.gomnd.ignored-files`,`linters.gomnd.ignored-functions`." )
367
377
}
368
378
369
379
// Deprecated since v1.47.0
370
380
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`." )
372
382
}
373
383
374
384
// Deprecated since v1.47.0
375
385
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`." )
377
387
}
378
388
379
389
// Deprecated since v1.47.0
380
390
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`." )
382
392
}
383
393
384
394
// Deprecated since v1.47.0
385
395
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`." )
387
397
}
388
398
}
389
399
@@ -408,14 +418,6 @@ func (l *Loader) handleEnableOnlyOption() error {
408
418
return nil
409
419
}
410
420
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
-
419
421
func customDecoderHook () viper.DecoderConfigOption {
420
422
return viper .DecodeHook (mapstructure .ComposeDecodeHookFunc (
421
423
// Default hooks (https://github.com/spf13/viper/blob/518241257478c557633ab36e474dfcaeb9a3c623/viper.go#L135-L138).
0 commit comments