Skip to content

Commit

Permalink
exhaustive: add missing config (golangci#3212)
Browse files Browse the repository at this point in the history
  • Loading branch information
maratori authored and SeigeC committed Apr 4, 2023
1 parent fc361cf commit 3ef8b2f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
9 changes: 7 additions & 2 deletions .golangci.reference.yml
Expand Up @@ -293,6 +293,11 @@ linters-settings:
comparison: false

exhaustive:
# Program elements to check for exhaustiveness.
# Default: [ switch ]
check:
- switch
- map
# Check switch statements in generated files also.
# Default: false
check-generated: true
Expand All @@ -307,10 +312,10 @@ linters-settings:
# Consider enums only in package scopes, not in inner scopes.
# Default: false
package-scope-only: true
# only run exhaustive check on switches with "//exhaustive:enforce" comment
# Only run exhaustive check on switches with "//exhaustive:enforce" comment.
# Default: false
explicit-exhaustive-switch: true
# only run exhaustive check on map literals with "//exhaustive:enforce" comment.
# Only run exhaustive check on map literals with "//exhaustive:enforce" comment.
# Default: false
explicit-exhaustive-map: true

Expand Down
16 changes: 10 additions & 6 deletions pkg/config/linters_settings.go
Expand Up @@ -25,10 +25,13 @@ var defaultLintersSettings = LintersSettings{
Comparison: true,
},
Exhaustive: ExhaustiveSettings{
Check: []string{"switch"},
CheckGenerated: false,
DefaultSignifiesExhaustive: false,
IgnoreEnumMembers: "",
PackageScopeOnly: false,
ExplicitExhaustiveMap: false,
ExplicitExhaustiveSwitch: false,
},
Forbidigo: ForbidigoSettings{
ExcludeGodocExamples: true,
Expand Down Expand Up @@ -274,12 +277,13 @@ type ErrorLintSettings struct {
}

type ExhaustiveSettings struct {
CheckGenerated bool `mapstructure:"check-generated"`
DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"`
IgnoreEnumMembers string `mapstructure:"ignore-enum-members"`
PackageScopeOnly bool `mapstructure:"package-scope-only"`
ExplicitExhaustiveMap bool `mapstructure:"explicit-exhaustive-map"`
ExplicitExhaustiveSwitch bool `mapstructure:"explicit-exhaustive-switch"`
Check []string `mapstructure:"check"`
CheckGenerated bool `mapstructure:"check-generated"`
DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"`
IgnoreEnumMembers string `mapstructure:"ignore-enum-members"`
PackageScopeOnly bool `mapstructure:"package-scope-only"`
ExplicitExhaustiveMap bool `mapstructure:"explicit-exhaustive-map"`
ExplicitExhaustiveSwitch bool `mapstructure:"explicit-exhaustive-switch"`
}

type ExhaustiveStructSettings struct {
Expand Down
6 changes: 4 additions & 2 deletions pkg/golinters/exhaustive.go
Expand Up @@ -15,11 +15,13 @@ func NewExhaustive(settings *config.ExhaustiveSettings) *goanalysis.Linter {
if settings != nil {
cfg = map[string]map[string]interface{}{
a.Name: {
exhaustive.CheckFlag: settings.Check,
exhaustive.CheckGeneratedFlag: settings.CheckGenerated,
exhaustive.DefaultSignifiesExhaustiveFlag: settings.DefaultSignifiesExhaustive,
exhaustive.ExplicitExhaustiveMapFlag: settings.ExplicitExhaustiveMap,
exhaustive.ExplicitExhaustiveSwitchFlag: settings.PackageScopeOnly,
exhaustive.IgnoreEnumMembersFlag: settings.IgnoreEnumMembers,
exhaustive.PackageScopeOnlyFlag: settings.PackageScopeOnly,
exhaustive.ExplicitExhaustiveMapFlag: settings.ExplicitExhaustiveMap,
exhaustive.ExplicitExhaustiveSwitchFlag: settings.ExplicitExhaustiveSwitch,
},
}
}
Expand Down

0 comments on commit 3ef8b2f

Please sign in to comment.