Skip to content

Commit 24b51ea

Browse files
authored
dev: use bool pointer on deprecated bool options (golangci#5254)
1 parent a6c26ee commit 24b51ea

File tree

8 files changed

+37
-34
lines changed

8 files changed

+37
-34
lines changed

pkg/commands/flagsets.go

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
5656

5757
internal.AddDeprecatedHackedStringSlice(fs, "skip-files", color.GreenString("Regexps of files to skip"))
5858
internal.AddDeprecatedHackedStringSlice(fs, "skip-dirs", color.GreenString("Regexps of directories to skip"))
59-
internal.AddDeprecatedFlagAndBind(v, fs, fs.Bool, "skip-dirs-use-default", "run.skip-dirs-use-default", true,
60-
formatList("Use or not use default excluded directories:", processors.StdExcludeDirRegexps))
6159

6260
const allowParallelDesc = "Allow multiple parallel golangci-lint instances running.\n" +
6361
"If false (default) - golangci-lint acquires file lock on start."

pkg/config/issues.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type Issues struct {
128128

129129
NeedFix bool `mapstructure:"fix"`
130130

131-
ExcludeGeneratedStrict bool `mapstructure:"exclude-generated-strict"` // Deprecated: use ExcludeGenerated instead.
131+
ExcludeGeneratedStrict *bool `mapstructure:"exclude-generated-strict"` // Deprecated: use ExcludeGenerated instead.
132132
}
133133

134134
func (i *Issues) Validate() error {

pkg/config/linters_settings.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ var defaultLintersSettings = LintersSettings{
169169
Unused: UnusedSettings{
170170
FieldWritesAreUses: true,
171171
PostStatementsAreReads: false,
172-
ExportedIsUsed: true,
173172
ExportedFieldsAreUsed: true,
174173
ParametersAreUsed: true,
175174
LocalVariablesAreUsed: true,
@@ -329,8 +328,10 @@ type BiDiChkSettings struct {
329328
}
330329

331330
type CopyLoopVarSettings struct {
332-
IgnoreAlias bool `mapstructure:"ignore-alias"` // Deprecated: use CheckAlias
333-
CheckAlias bool `mapstructure:"check-alias"`
331+
CheckAlias bool `mapstructure:"check-alias"`
332+
333+
// Deprecated: use CheckAlias
334+
IgnoreAlias *bool `mapstructure:"ignore-alias"`
334335
}
335336

336337
type Cyclop struct {
@@ -548,7 +549,7 @@ type GodotSettings struct {
548549
Period bool `mapstructure:"period"`
549550

550551
// Deprecated: use Scope instead
551-
CheckAll bool `mapstructure:"check-all"`
552+
CheckAll *bool `mapstructure:"check-all"`
552553
}
553554

554555
type GodoxSettings struct {
@@ -641,7 +642,7 @@ type GovetSettings struct {
641642
Settings map[string]map[string]any
642643

643644
// Deprecated: the linter should be enabled inside Enable.
644-
CheckShadowing bool `mapstructure:"check-shadowing"`
645+
CheckShadowing *bool `mapstructure:"check-shadowing"`
645646
}
646647

647648
func (cfg *GovetSettings) Validate() error {
@@ -857,7 +858,7 @@ type SlogLintSettings struct {
857858
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
858859

859860
// Deprecated: use Context instead.
860-
ContextOnly bool `mapstructure:"context-only"`
861+
ContextOnly *bool `mapstructure:"context-only"`
861862
}
862863

863864
type SpancheckSettings struct {
@@ -977,11 +978,14 @@ type UseStdlibVarsSettings struct {
977978
TimeLayout bool `mapstructure:"time-layout"`
978979
CryptoHash bool `mapstructure:"crypto-hash"`
979980
DefaultRPCPath bool `mapstructure:"default-rpc-path"`
980-
OSDevNull bool `mapstructure:"os-dev-null"` // Deprecated
981981
SQLIsolationLevel bool `mapstructure:"sql-isolation-level"`
982982
TLSSignatureScheme bool `mapstructure:"tls-signature-scheme"`
983983
ConstantKind bool `mapstructure:"constant-kind"`
984-
SyslogPriority bool `mapstructure:"syslog-priority"` // Deprecated
984+
985+
// Deprecated
986+
OSDevNull *bool `mapstructure:"os-dev-null"`
987+
// Deprecated
988+
SyslogPriority *bool `mapstructure:"syslog-priority"`
985989
}
986990

987991
type UseTestingSettings struct {
@@ -1007,11 +1011,13 @@ type UnparamSettings struct {
10071011
type UnusedSettings struct {
10081012
FieldWritesAreUses bool `mapstructure:"field-writes-are-uses"`
10091013
PostStatementsAreReads bool `mapstructure:"post-statements-are-reads"`
1010-
ExportedIsUsed bool `mapstructure:"exported-is-used"` // Deprecated
10111014
ExportedFieldsAreUsed bool `mapstructure:"exported-fields-are-used"`
10121015
ParametersAreUsed bool `mapstructure:"parameters-are-used"`
10131016
LocalVariablesAreUsed bool `mapstructure:"local-variables-are-used"`
10141017
GeneratedIsUsed bool `mapstructure:"generated-is-used"`
1018+
1019+
// Deprecated
1020+
ExportedIsUsed *bool `mapstructure:"exported-is-used"`
10151021
}
10161022

10171023
type VarnamelenSettings struct {

pkg/config/loader.go

+15-16
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ func (l *Loader) handleGoVersion() {
304304
os.Setenv("GOSECGOVERSION", l.cfg.Run.Go)
305305
}
306306

307-
//nolint:gocyclo // The complexity is expected by the cases to handle.
308307
func (l *Loader) handleDeprecation() error {
309308
if l.cfg.InternalTest || l.cfg.InternalCmdTest || os.Getenv(logutils.EnvTestRun) == "1" {
310309
return nil
@@ -322,19 +321,17 @@ func (l *Loader) handleDeprecation() error {
322321
l.cfg.Issues.ExcludeDirs = l.cfg.Run.SkipDirs
323322
}
324323

325-
// The 2 options are true by default.
326324
// Deprecated since v1.57.0
327-
if !l.cfg.Run.UseDefaultSkipDirs {
325+
if l.cfg.Run.UseDefaultSkipDirs != nil {
328326
l.log.Warnf("The configuration option `run.skip-dirs-use-default` is deprecated, please use `issues.exclude-dirs-use-default`.")
327+
l.cfg.Issues.UseDefaultExcludeDirs = *l.cfg.Run.UseDefaultSkipDirs
329328
}
330-
l.cfg.Issues.UseDefaultExcludeDirs = l.cfg.Run.UseDefaultSkipDirs && l.cfg.Issues.UseDefaultExcludeDirs
331329

332-
// The 2 options are false by default.
333330
// Deprecated since v1.57.0
334-
if l.cfg.Run.ShowStats {
331+
if l.cfg.Run.ShowStats != nil {
335332
l.log.Warnf("The configuration option `run.show-stats` is deprecated, please use `output.show-stats`")
333+
l.cfg.Output.ShowStats = *l.cfg.Run.ShowStats
336334
}
337-
l.cfg.Output.ShowStats = l.cfg.Run.ShowStats || l.cfg.Output.ShowStats
338335

339336
// Deprecated since v1.63.0
340337
if l.cfg.Output.UniqByLine != nil {
@@ -363,9 +360,11 @@ func (l *Loader) handleDeprecation() error {
363360
}
364361

365362
// Deprecated since v1.59.0
366-
if l.cfg.Issues.ExcludeGeneratedStrict {
363+
if l.cfg.Issues.ExcludeGeneratedStrict != nil {
367364
l.log.Warnf("The configuration option `issues.exclude-generated-strict` is deprecated, please use `issues.exclude-generated`")
368-
l.cfg.Issues.ExcludeGenerated = "strict" // Don't use the constants to avoid cyclic dependencies.
365+
if !*l.cfg.Issues.ExcludeGeneratedStrict {
366+
l.cfg.Issues.ExcludeGenerated = "strict" // Don't use the constants to avoid cyclic dependencies.
367+
}
369368
}
370369

371370
l.handleLinterOptionDeprecations()
@@ -376,12 +375,12 @@ func (l *Loader) handleDeprecation() error {
376375
func (l *Loader) handleLinterOptionDeprecations() {
377376
// Deprecated since v1.57.0,
378377
// but it was unofficially deprecated since v1.19 (2019) (https://github.com/golangci/golangci-lint/pull/697).
379-
if l.cfg.LintersSettings.Govet.CheckShadowing {
378+
if l.cfg.LintersSettings.Govet.CheckShadowing != nil {
380379
l.log.Warnf("The configuration option `linters.govet.check-shadowing` is deprecated. " +
381380
"Please enable `shadow` instead, if you are not using `enable-all`.")
382381
}
383382

384-
if l.cfg.LintersSettings.CopyLoopVar.IgnoreAlias {
383+
if l.cfg.LintersSettings.CopyLoopVar.IgnoreAlias != nil {
385384
l.log.Warnf("The configuration option `linters.copyloopvar.ignore-alias` is deprecated and ignored," +
386385
"please use `linters.copyloopvar.check-alias`.")
387386
}
@@ -403,7 +402,7 @@ func (l *Loader) handleLinterOptionDeprecations() {
403402
}
404403

405404
// Deprecated since v1.33.0.
406-
if l.cfg.LintersSettings.Godot.CheckAll {
405+
if l.cfg.LintersSettings.Godot.CheckAll != nil {
407406
l.log.Warnf("The configuration option `linters.godot.check-all` is deprecated, please use `linters.godot.scope: all`.")
408407
}
409408

@@ -428,23 +427,23 @@ func (l *Loader) handleLinterOptionDeprecations() {
428427
}
429428

430429
// Deprecated since v1.60.0
431-
if !l.cfg.LintersSettings.Unused.ExportedIsUsed {
430+
if l.cfg.LintersSettings.Unused.ExportedIsUsed != nil {
432431
l.log.Warnf("The configuration option `linters.unused.exported-is-used` is deprecated.")
433432
}
434433

435434
// Deprecated since v1.58.0
436-
if l.cfg.LintersSettings.SlogLint.ContextOnly {
435+
if l.cfg.LintersSettings.SlogLint.ContextOnly != nil {
437436
l.log.Warnf("The configuration option `linters.sloglint.context-only` is deprecated, please use `linters.sloglint.context`.")
438437
l.cfg.LintersSettings.SlogLint.Context = cmp.Or(l.cfg.LintersSettings.SlogLint.Context, "all")
439438
}
440439

441440
// Deprecated since v1.51.0
442-
if l.cfg.LintersSettings.UseStdlibVars.OSDevNull {
441+
if l.cfg.LintersSettings.UseStdlibVars.OSDevNull != nil {
443442
l.log.Warnf("The configuration option `linters.usestdlibvars.os-dev-null` is deprecated.")
444443
}
445444

446445
// Deprecated since v1.51.0
447-
if l.cfg.LintersSettings.UseStdlibVars.SyslogPriority {
446+
if l.cfg.LintersSettings.UseStdlibVars.SyslogPriority != nil {
448447
l.log.Warnf("The configuration option `linters.usestdlibvars.syslog-priority` is deprecated.")
449448
}
450449
}

pkg/config/run.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ type Run struct {
2929
// Deprecated: use Issues.ExcludeDirs instead.
3030
SkipDirs []string `mapstructure:"skip-dirs"`
3131
// Deprecated: use Issues.UseDefaultExcludeDirs instead.
32-
UseDefaultSkipDirs bool `mapstructure:"skip-dirs-use-default"`
32+
UseDefaultSkipDirs *bool `mapstructure:"skip-dirs-use-default"`
3333

3434
// Deprecated: use Output.ShowStats instead.
35-
ShowStats bool `mapstructure:"show-stats"`
35+
ShowStats *bool `mapstructure:"show-stats"`
3636
}
3737

3838
func (r *Run) Validate() error {

pkg/golinters/godot/godot.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func New(settings *config.GodotSettings) *goanalysis.Linter {
2424
}
2525

2626
// Convert deprecated setting
27-
if settings.CheckAll {
27+
if settings.CheckAll != nil && *settings.CheckAll {
2828
dotSettings.Scope = godot.AllScope
2929
}
3030
}

pkg/golinters/govet/govet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func isAnalyzerEnabled(name string, cfg *config.GovetSettings, defaultAnalyzers
190190
}
191191

192192
// Keeping for backward compatibility.
193-
if cfg.CheckShadowing && name == shadow.Analyzer.Name {
193+
if cfg.CheckShadowing != nil && *cfg.CheckShadowing && name == shadow.Analyzer.Name {
194194
return true
195195
}
196196

pkg/golinters/usestdlibvars/usestdlibvars.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ func New(settings *config.UseStdlibVarsSettings) *goanalysis.Linter {
1818
analyzer.CryptoHashFlag: settings.CryptoHash,
1919
analyzer.HTTPMethodFlag: settings.HTTPMethod,
2020
analyzer.HTTPStatusCodeFlag: settings.HTTPStatusCode,
21-
analyzer.OSDevNullFlag: settings.OSDevNull,
21+
analyzer.OSDevNullFlag: settings.OSDevNull != nil && *settings.OSDevNull,
2222
analyzer.RPCDefaultPathFlag: settings.DefaultRPCPath,
2323
analyzer.SQLIsolationLevelFlag: settings.SQLIsolationLevel,
24-
analyzer.SyslogPriorityFlag: settings.SyslogPriority,
24+
analyzer.SyslogPriorityFlag: settings.SyslogPriority != nil && *settings.SyslogPriority,
2525
analyzer.TimeLayoutFlag: settings.TimeLayout,
2626
analyzer.TimeMonthFlag: settings.TimeMonth,
2727
analyzer.TimeWeekdayFlag: settings.TimeWeekday,

0 commit comments

Comments
 (0)