exhaustive: add missing config (#3212)

This commit is contained in:
Marat Reymers 2022-09-11 20:07:37 +03:00 committed by GitHub
parent 1f155b7ef6
commit 8a3b754ca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -293,6 +293,11 @@ linters-settings:
comparison: false comparison: false
exhaustive: exhaustive:
# Program elements to check for exhaustiveness.
# Default: [ switch ]
check:
- switch
- map
# Check switch statements in generated files also. # Check switch statements in generated files also.
# Default: false # Default: false
check-generated: true check-generated: true
@ -307,10 +312,10 @@ linters-settings:
# Consider enums only in package scopes, not in inner scopes. # Consider enums only in package scopes, not in inner scopes.
# Default: false # Default: false
package-scope-only: true 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 # Default: false
explicit-exhaustive-switch: true 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 # Default: false
explicit-exhaustive-map: true explicit-exhaustive-map: true

View File

@ -25,10 +25,13 @@ var defaultLintersSettings = LintersSettings{
Comparison: true, Comparison: true,
}, },
Exhaustive: ExhaustiveSettings{ Exhaustive: ExhaustiveSettings{
Check: []string{"switch"},
CheckGenerated: false, CheckGenerated: false,
DefaultSignifiesExhaustive: false, DefaultSignifiesExhaustive: false,
IgnoreEnumMembers: "", IgnoreEnumMembers: "",
PackageScopeOnly: false, PackageScopeOnly: false,
ExplicitExhaustiveMap: false,
ExplicitExhaustiveSwitch: false,
}, },
Forbidigo: ForbidigoSettings{ Forbidigo: ForbidigoSettings{
ExcludeGodocExamples: true, ExcludeGodocExamples: true,
@ -274,6 +277,7 @@ type ErrorLintSettings struct {
} }
type ExhaustiveSettings struct { type ExhaustiveSettings struct {
Check []string `mapstructure:"check"`
CheckGenerated bool `mapstructure:"check-generated"` CheckGenerated bool `mapstructure:"check-generated"`
DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"` DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"`
IgnoreEnumMembers string `mapstructure:"ignore-enum-members"` IgnoreEnumMembers string `mapstructure:"ignore-enum-members"`

View File

@ -15,11 +15,13 @@ func NewExhaustive(settings *config.ExhaustiveSettings) *goanalysis.Linter {
if settings != nil { if settings != nil {
cfg = map[string]map[string]interface{}{ cfg = map[string]map[string]interface{}{
a.Name: { a.Name: {
exhaustive.CheckFlag: settings.Check,
exhaustive.CheckGeneratedFlag: settings.CheckGenerated, exhaustive.CheckGeneratedFlag: settings.CheckGenerated,
exhaustive.DefaultSignifiesExhaustiveFlag: settings.DefaultSignifiesExhaustive, exhaustive.DefaultSignifiesExhaustiveFlag: settings.DefaultSignifiesExhaustive,
exhaustive.ExplicitExhaustiveMapFlag: settings.ExplicitExhaustiveMap,
exhaustive.ExplicitExhaustiveSwitchFlag: settings.PackageScopeOnly,
exhaustive.IgnoreEnumMembersFlag: settings.IgnoreEnumMembers, exhaustive.IgnoreEnumMembersFlag: settings.IgnoreEnumMembers,
exhaustive.PackageScopeOnlyFlag: settings.PackageScopeOnly,
exhaustive.ExplicitExhaustiveMapFlag: settings.ExplicitExhaustiveMap,
exhaustive.ExplicitExhaustiveSwitchFlag: settings.ExplicitExhaustiveSwitch,
}, },
} }
} }