Skip to content

Commit 8a3b754

Browse files
authored
exhaustive: add missing config (#3212)
1 parent 1f155b7 commit 8a3b754

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

.golangci.reference.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ linters-settings:
293293
comparison: false
294294

295295
exhaustive:
296+
# Program elements to check for exhaustiveness.
297+
# Default: [ switch ]
298+
check:
299+
- switch
300+
- map
296301
# Check switch statements in generated files also.
297302
# Default: false
298303
check-generated: true
@@ -307,10 +312,10 @@ linters-settings:
307312
# Consider enums only in package scopes, not in inner scopes.
308313
# Default: false
309314
package-scope-only: true
310-
# only run exhaustive check on switches with "//exhaustive:enforce" comment
315+
# Only run exhaustive check on switches with "//exhaustive:enforce" comment.
311316
# Default: false
312317
explicit-exhaustive-switch: true
313-
# only run exhaustive check on map literals with "//exhaustive:enforce" comment.
318+
# Only run exhaustive check on map literals with "//exhaustive:enforce" comment.
314319
# Default: false
315320
explicit-exhaustive-map: true
316321

pkg/config/linters_settings.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ var defaultLintersSettings = LintersSettings{
2525
Comparison: true,
2626
},
2727
Exhaustive: ExhaustiveSettings{
28+
Check: []string{"switch"},
2829
CheckGenerated: false,
2930
DefaultSignifiesExhaustive: false,
3031
IgnoreEnumMembers: "",
3132
PackageScopeOnly: false,
33+
ExplicitExhaustiveMap: false,
34+
ExplicitExhaustiveSwitch: false,
3235
},
3336
Forbidigo: ForbidigoSettings{
3437
ExcludeGodocExamples: true,
@@ -274,12 +277,13 @@ type ErrorLintSettings struct {
274277
}
275278

276279
type ExhaustiveSettings struct {
277-
CheckGenerated bool `mapstructure:"check-generated"`
278-
DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"`
279-
IgnoreEnumMembers string `mapstructure:"ignore-enum-members"`
280-
PackageScopeOnly bool `mapstructure:"package-scope-only"`
281-
ExplicitExhaustiveMap bool `mapstructure:"explicit-exhaustive-map"`
282-
ExplicitExhaustiveSwitch bool `mapstructure:"explicit-exhaustive-switch"`
280+
Check []string `mapstructure:"check"`
281+
CheckGenerated bool `mapstructure:"check-generated"`
282+
DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"`
283+
IgnoreEnumMembers string `mapstructure:"ignore-enum-members"`
284+
PackageScopeOnly bool `mapstructure:"package-scope-only"`
285+
ExplicitExhaustiveMap bool `mapstructure:"explicit-exhaustive-map"`
286+
ExplicitExhaustiveSwitch bool `mapstructure:"explicit-exhaustive-switch"`
283287
}
284288

285289
type ExhaustiveStructSettings struct {

pkg/golinters/exhaustive.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ func NewExhaustive(settings *config.ExhaustiveSettings) *goanalysis.Linter {
1515
if settings != nil {
1616
cfg = map[string]map[string]interface{}{
1717
a.Name: {
18+
exhaustive.CheckFlag: settings.Check,
1819
exhaustive.CheckGeneratedFlag: settings.CheckGenerated,
1920
exhaustive.DefaultSignifiesExhaustiveFlag: settings.DefaultSignifiesExhaustive,
20-
exhaustive.ExplicitExhaustiveMapFlag: settings.ExplicitExhaustiveMap,
21-
exhaustive.ExplicitExhaustiveSwitchFlag: settings.PackageScopeOnly,
2221
exhaustive.IgnoreEnumMembersFlag: settings.IgnoreEnumMembers,
22+
exhaustive.PackageScopeOnlyFlag: settings.PackageScopeOnly,
23+
exhaustive.ExplicitExhaustiveMapFlag: settings.ExplicitExhaustiveMap,
24+
exhaustive.ExplicitExhaustiveSwitchFlag: settings.ExplicitExhaustiveSwitch,
2325
},
2426
}
2527
}

0 commit comments

Comments
 (0)