Skip to content

Commit 50fb95e

Browse files
committed
dev: option to not check deprecation
1 parent d318327 commit 50fb95e

File tree

5 files changed

+34
-52
lines changed

5 files changed

+34
-52
lines changed

.golangci.yml

-9
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,11 @@ issues:
161161
- path: pkg/commands/run.go
162162
linters: [staticcheck]
163163
text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead."
164-
- path: pkg/commands/config.go
165-
linters: [staticcheck]
166-
text: "SA1019: cfg.Run.UseDefaultSkipDirs is deprecated: use Issues.UseDefaultExcludeDirs instead."
167-
- path: pkg/commands/linters.go
168-
linters: [staticcheck]
169-
text: "SA1019: c.cfg.Run.UseDefaultSkipDirs is deprecated: use Issues.UseDefaultExcludeDirs instead."
170164

171165
# Deprecated linter options.
172166
- path: pkg/golinters/errcheck.go
173167
linters: [staticcheck]
174168
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
175-
- path: pkg/commands/run.go
176-
linters: [staticcheck]
177-
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
178169
- path: pkg/golinters/govet.go
179170
linters: [staticcheck]
180171
text: "SA1019: cfg.CheckShadowing is deprecated: the linter should be enabled inside Enable."

pkg/commands/config.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,10 @@ func (c *configCommand) preRunE(cmd *cobra.Command, args []string) error {
8484
// It only needs to know the path of the configuration file.
8585
cfg := config.NewDefault()
8686

87-
// Hack to hide deprecation messages related to `--skip-dirs-use-default`:
88-
// Flags are not bound then the default values, defined only through flags, are not applied.
89-
// In this command, file path and file information are the only requirements, i.e. it don't need flag values.
90-
//
91-
// TODO(ldez) add an option (check deprecation) to `Loader.Load()` but this require a dedicated PR.
92-
cfg.Run.UseDefaultSkipDirs = true
93-
9487
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts, cfg, args)
9588

96-
if err := loader.Load(); err != nil {
89+
err := loader.Load(config.LoadOptions{})
90+
if err != nil {
9791
return fmt.Errorf("can't load config: %w", err)
9892
}
9993

pkg/commands/linters.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,10 @@ func newLintersCommand(logger logutils.Log) *lintersCommand {
5959
}
6060

6161
func (c *lintersCommand) preRunE(cmd *cobra.Command, args []string) error {
62-
// Hack to hide deprecation messages related to `--skip-dirs-use-default`:
63-
// Flags are not bound then the default values, defined only through flags, are not applied.
64-
// In this command, linters information are the only requirements, i.e. it don't need flag values.
65-
//
66-
// TODO(ldez) add an option (check deprecation) to `Loader.Load()` but this require a dedicated PR.
67-
c.cfg.Run.UseDefaultSkipDirs = true
68-
6962
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
7063

71-
if err := loader.Load(); err != nil {
64+
err := loader.Load(config.LoadOptions{})
65+
if err != nil {
7266
return fmt.Errorf("can't load config: %w", err)
7367
}
7468

pkg/commands/run.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ 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-
if err := loader.Load(); err != nil {
157+
err := loader.Load(config.LoadOptions{CheckDeprecation: true})
158+
if err != nil {
158159
return fmt.Errorf("can't load config: %w", err)
159160
}
160161

pkg/config/loader.go

+28-26
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ type LoaderOptions struct {
2424
NoConfig bool // Flag only.
2525
}
2626

27+
type LoadOptions struct {
28+
CheckDeprecation bool
29+
}
30+
2731
type 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

295301
func (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-
419421
func 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

Comments
 (0)