Skip to content

dev: use bool pointer on deprecated bool options #5254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkg/commands/flagsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {

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

const allowParallelDesc = "Allow multiple parallel golangci-lint instances running.\n" +
"If false (default) - golangci-lint acquires file lock on start."
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type Issues struct {

NeedFix bool `mapstructure:"fix"`

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

func (i *Issues) Validate() error {
Expand Down
24 changes: 15 additions & 9 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ var defaultLintersSettings = LintersSettings{
Unused: UnusedSettings{
FieldWritesAreUses: true,
PostStatementsAreReads: false,
ExportedIsUsed: true,
ExportedFieldsAreUsed: true,
ParametersAreUsed: true,
LocalVariablesAreUsed: true,
Expand Down Expand Up @@ -329,8 +328,10 @@ type BiDiChkSettings struct {
}

type CopyLoopVarSettings struct {
IgnoreAlias bool `mapstructure:"ignore-alias"` // Deprecated: use CheckAlias
CheckAlias bool `mapstructure:"check-alias"`
CheckAlias bool `mapstructure:"check-alias"`

// Deprecated: use CheckAlias
IgnoreAlias *bool `mapstructure:"ignore-alias"`
}

type Cyclop struct {
Expand Down Expand Up @@ -548,7 +549,7 @@ type GodotSettings struct {
Period bool `mapstructure:"period"`

// Deprecated: use Scope instead
CheckAll bool `mapstructure:"check-all"`
CheckAll *bool `mapstructure:"check-all"`
}

type GodoxSettings struct {
Expand Down Expand Up @@ -641,7 +642,7 @@ type GovetSettings struct {
Settings map[string]map[string]any

// Deprecated: the linter should be enabled inside Enable.
CheckShadowing bool `mapstructure:"check-shadowing"`
CheckShadowing *bool `mapstructure:"check-shadowing"`
}

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

// Deprecated: use Context instead.
ContextOnly bool `mapstructure:"context-only"`
ContextOnly *bool `mapstructure:"context-only"`
}

type SpancheckSettings struct {
Expand Down Expand Up @@ -977,11 +978,14 @@ type UseStdlibVarsSettings struct {
TimeLayout bool `mapstructure:"time-layout"`
CryptoHash bool `mapstructure:"crypto-hash"`
DefaultRPCPath bool `mapstructure:"default-rpc-path"`
OSDevNull bool `mapstructure:"os-dev-null"` // Deprecated
SQLIsolationLevel bool `mapstructure:"sql-isolation-level"`
TLSSignatureScheme bool `mapstructure:"tls-signature-scheme"`
ConstantKind bool `mapstructure:"constant-kind"`
SyslogPriority bool `mapstructure:"syslog-priority"` // Deprecated

// Deprecated
OSDevNull *bool `mapstructure:"os-dev-null"`
// Deprecated
SyslogPriority *bool `mapstructure:"syslog-priority"`
}

type UseTestingSettings struct {
Expand All @@ -1007,11 +1011,13 @@ type UnparamSettings struct {
type UnusedSettings struct {
FieldWritesAreUses bool `mapstructure:"field-writes-are-uses"`
PostStatementsAreReads bool `mapstructure:"post-statements-are-reads"`
ExportedIsUsed bool `mapstructure:"exported-is-used"` // Deprecated
ExportedFieldsAreUsed bool `mapstructure:"exported-fields-are-used"`
ParametersAreUsed bool `mapstructure:"parameters-are-used"`
LocalVariablesAreUsed bool `mapstructure:"local-variables-are-used"`
GeneratedIsUsed bool `mapstructure:"generated-is-used"`

// Deprecated
ExportedIsUsed *bool `mapstructure:"exported-is-used"`
}

type VarnamelenSettings struct {
Expand Down
31 changes: 15 additions & 16 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ func (l *Loader) handleGoVersion() {
os.Setenv("GOSECGOVERSION", l.cfg.Run.Go)
}

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

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

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

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

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

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

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

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

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

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

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

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

// Deprecated since v1.51.0
if l.cfg.LintersSettings.UseStdlibVars.SyslogPriority {
if l.cfg.LintersSettings.UseStdlibVars.SyslogPriority != nil {
l.log.Warnf("The configuration option `linters.usestdlibvars.syslog-priority` is deprecated.")
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ type Run struct {
// Deprecated: use Issues.ExcludeDirs instead.
SkipDirs []string `mapstructure:"skip-dirs"`
// Deprecated: use Issues.UseDefaultExcludeDirs instead.
UseDefaultSkipDirs bool `mapstructure:"skip-dirs-use-default"`
UseDefaultSkipDirs *bool `mapstructure:"skip-dirs-use-default"`

// Deprecated: use Output.ShowStats instead.
ShowStats bool `mapstructure:"show-stats"`
ShowStats *bool `mapstructure:"show-stats"`
}

func (r *Run) Validate() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/godot/godot.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func New(settings *config.GodotSettings) *goanalysis.Linter {
}

// Convert deprecated setting
if settings.CheckAll {
if settings.CheckAll != nil && *settings.CheckAll {
dotSettings.Scope = godot.AllScope
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/govet/govet.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func isAnalyzerEnabled(name string, cfg *config.GovetSettings, defaultAnalyzers
}

// Keeping for backward compatibility.
if cfg.CheckShadowing && name == shadow.Analyzer.Name {
if cfg.CheckShadowing != nil && *cfg.CheckShadowing && name == shadow.Analyzer.Name {
return true
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/golinters/usestdlibvars/usestdlibvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func New(settings *config.UseStdlibVarsSettings) *goanalysis.Linter {
analyzer.CryptoHashFlag: settings.CryptoHash,
analyzer.HTTPMethodFlag: settings.HTTPMethod,
analyzer.HTTPStatusCodeFlag: settings.HTTPStatusCode,
analyzer.OSDevNullFlag: settings.OSDevNull,
analyzer.OSDevNullFlag: settings.OSDevNull != nil && *settings.OSDevNull,
analyzer.RPCDefaultPathFlag: settings.DefaultRPCPath,
analyzer.SQLIsolationLevelFlag: settings.SQLIsolationLevel,
analyzer.SyslogPriorityFlag: settings.SyslogPriority,
analyzer.SyslogPriorityFlag: settings.SyslogPriority != nil && *settings.SyslogPriority,
analyzer.TimeLayoutFlag: settings.TimeLayout,
analyzer.TimeMonthFlag: settings.TimeMonth,
analyzer.TimeWeekdayFlag: settings.TimeWeekday,
Expand Down
Loading