Skip to content
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

exhaustive: add missing config #3212

Merged
merged 1 commit into from Sep 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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