Skip to content

Commit 6c573e1

Browse files
committed
dev: option to not check deprecation
1 parent 288c847 commit 6c573e1

File tree

5 files changed

+16
-30
lines changed

5 files changed

+16
-30
lines changed

.golangci.yml

-9
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,11 @@ issues:
159159
- path: pkg/commands/run.go
160160
linters: [staticcheck]
161161
text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead."
162-
- path: pkg/commands/config.go
163-
linters: [staticcheck]
164-
text: "SA1019: cfg.Run.UseDefaultSkipDirs is deprecated: use Issues.UseDefaultExcludeDirs instead."
165-
- path: pkg/commands/linters.go
166-
linters: [staticcheck]
167-
text: "SA1019: c.cfg.Run.UseDefaultSkipDirs is deprecated: use Issues.UseDefaultExcludeDirs instead."
168162

169163
# Deprecated linter options.
170164
- path: pkg/golinters/errcheck.go
171165
linters: [staticcheck]
172166
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
173-
- path: pkg/commands/run.go
174-
linters: [staticcheck]
175-
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
176167
- path: pkg/golinters/govet.go
177168
linters: [staticcheck]
178169
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
@@ -82,16 +82,10 @@ func (c *configCommand) preRunE(cmd *cobra.Command, args []string) error {
8282
// It only needs to know the path of the configuration file.
8383
cfg := config.NewDefault()
8484

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

94-
if err := loader.Load(); err != nil {
87+
err := loader.Load(config.LoadOptions{})
88+
if err != nil {
9589
return fmt.Errorf("can't load config: %w", err)
9690
}
9791

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

+10-4
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()

0 commit comments

Comments
 (0)