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