From 49a50c2e08214192c9a415306e97144a456bd29c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Nov 2021 20:10:48 +0000 Subject: [PATCH 1/3] build(deps): bump github.com/nishanths/exhaustive from 0.3.6 to 0.6.0 Bumps [github.com/nishanths/exhaustive](https://github.com/nishanths/exhaustive) from 0.3.6 to 0.6.0. - [Release notes](https://github.com/nishanths/exhaustive/releases) - [Commits](https://github.com/nishanths/exhaustive/compare/v0.3.6...v0.6.0) --- updated-dependencies: - dependency-name: github.com/nishanths/exhaustive dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 57507bbdec05..849b1c0b93a1 100644 --- a/go.mod +++ b/go.mod @@ -59,7 +59,7 @@ require ( github.com/mitchellh/go-ps v1.0.0 github.com/moricho/tparallel v0.2.1 github.com/nakabonne/nestif v0.3.1 - github.com/nishanths/exhaustive v0.3.6 + github.com/nishanths/exhaustive v0.6.0 github.com/nishanths/predeclared v0.2.1 github.com/pkg/errors v0.9.1 github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349 diff --git a/go.sum b/go.sum index 07c263de35e8..6157dd38a8c7 100644 --- a/go.sum +++ b/go.sum @@ -550,8 +550,8 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354 h1:4kuARK6Y6Fx github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354/go.mod h1:KSVJerMDfblTH7p5MZaTt+8zaT2iEk3AkVb9PQdZuE8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/nishanths/exhaustive v0.3.6 h1:uRVZUfvWqSsPv+w4Qv30WgWdJwGOqR1P7QCwyhiKbOs= -github.com/nishanths/exhaustive v0.3.6/go.mod h1:gX+MP7DWMKJmNa1HfMozK+u04hQd3na9i0hyqf3/dOI= +github.com/nishanths/exhaustive v0.6.0 h1:twt0QXhWjFMYGalECxdWM8Hv5Zh2SjQ5Fu+uSuUXWLM= +github.com/nishanths/exhaustive v0.6.0/go.mod h1:gX+MP7DWMKJmNa1HfMozK+u04hQd3na9i0hyqf3/dOI= github.com/nishanths/predeclared v0.0.0-20190419143655-18a43bb90ffc/go.mod h1:62PewwiQTlm/7Rj+cxVYqZvDIUc+JjZq6GHAC1fsObQ= github.com/nishanths/predeclared v0.2.1 h1:1TXtjmy4f3YCFjTxRd8zcFHOmoUir+gp0ESzjFzG2sw= github.com/nishanths/predeclared v0.2.1/go.mod h1:HvkGJcA3naj4lOwnFXFDkFxVtSqQMB9sbB1usJ+xjQE= From 337d7304a3962fd5a8547906a6f6c9a4376d5bf1 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 9 Nov 2021 01:15:39 +0100 Subject: [PATCH 2/3] remove tests on removed/deprecated flags --- .../exhaustive_checking_strategy_name.yml | 3 --- .../exhaustive_checking_strategy_value.yml | 3 --- .../exhaustive_checking_strategy_name.go | 18 --------------- .../exhaustive_checking_strategy_value.go | 22 ------------------- 4 files changed, 46 deletions(-) delete mode 100644 test/testdata/configs/exhaustive_checking_strategy_name.yml delete mode 100644 test/testdata/configs/exhaustive_checking_strategy_value.yml delete mode 100644 test/testdata/exhaustive_checking_strategy_name.go delete mode 100644 test/testdata/exhaustive_checking_strategy_value.go diff --git a/test/testdata/configs/exhaustive_checking_strategy_name.yml b/test/testdata/configs/exhaustive_checking_strategy_name.yml deleted file mode 100644 index dca93cab4e5d..000000000000 --- a/test/testdata/configs/exhaustive_checking_strategy_name.yml +++ /dev/null @@ -1,3 +0,0 @@ -linters-settings: - exhaustive: - checking-strategy: "name" diff --git a/test/testdata/configs/exhaustive_checking_strategy_value.yml b/test/testdata/configs/exhaustive_checking_strategy_value.yml deleted file mode 100644 index dd64f0581e9c..000000000000 --- a/test/testdata/configs/exhaustive_checking_strategy_value.yml +++ /dev/null @@ -1,3 +0,0 @@ -linters-settings: - exhaustive: - checking-strategy: "value" diff --git a/test/testdata/exhaustive_checking_strategy_name.go b/test/testdata/exhaustive_checking_strategy_name.go deleted file mode 100644 index 55bf12675046..000000000000 --- a/test/testdata/exhaustive_checking_strategy_name.go +++ /dev/null @@ -1,18 +0,0 @@ -//args: -Eexhaustive -//config_path: testdata/configs/exhaustive_checking_strategy_name.yml -package testdata - -type AccessControl string - -const ( - AccessPublic AccessControl = "public" - AccessPrivate AccessControl = "private" - AccessDefault AccessControl = AccessPublic -) - -func example(v AccessControl) { - switch v { // ERROR "missing cases in switch of type AccessControl: AccessDefault" - case AccessPublic: - case AccessPrivate: - } -} diff --git a/test/testdata/exhaustive_checking_strategy_value.go b/test/testdata/exhaustive_checking_strategy_value.go deleted file mode 100644 index 7e1688190de9..000000000000 --- a/test/testdata/exhaustive_checking_strategy_value.go +++ /dev/null @@ -1,22 +0,0 @@ -//args: -Eexhaustive -//config_path: testdata/configs/exhaustive_checking_strategy_value.yml -package testdata - -type AccessControl string - -const ( - AccessPublic AccessControl = "public" - AccessPrivate AccessControl = "private" - AccessDefault AccessControl = AccessPublic -) - -// Expect no diagnostics for this switch statement, even though AccessDefault is -// not listed, because AccessPublic (which is listed) has the same value as -// AccessDefault. - -func example(v AccessControl) { - switch v { - case AccessPublic: - case AccessPrivate: - } -} From 65b7f7be37f9b3f38154d1d74c31597fa2ca7ec5 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 9 Nov 2021 01:27:49 +0100 Subject: [PATCH 3/3] feat: add new flag --- .golangci.example.yml | 6 ++---- pkg/config/linters_settings.go | 6 ++++-- pkg/golinters/exhaustive.go | 6 ++++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.golangci.example.yml b/.golangci.example.yml index 5ac4cd13c893..3a2f750ace85 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -154,10 +154,8 @@ linters-settings: # enum members matching the supplied regex do not have to be listed in # switch statements to satisfy exhaustiveness ignore-enum-members: "" - # strategy to use when checking exhaustiveness of switch statements; one of: - # "name", "value"; see documentation for details: - # https://pkg.go.dev/github.com/nishanths/exhaustive#section-documentation - checking-strategy: "value" + # consider enums only in package scopes, not in inner scopes + package-scope-only: false exhaustivestruct: # Struct Patterns is list of expressions to match struct packages and names diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 192e6d8e9226..9a26ca06a4ba 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -199,9 +199,11 @@ type ErrorLintSettings struct { type ExhaustiveSettings struct { CheckGenerated bool `mapstructure:"check-generated"` DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"` - IgnorePattern string `mapstructure:"ignore-pattern"` // Deprecated: this setting has no effect; see IgnoreEnumMembers instead. IgnoreEnumMembers string `mapstructure:"ignore-enum-members"` - CheckingStrategy string `mapstructure:"checking-strategy"` + PackageScopeOnly bool `mapstructure:"package-scope-only"` + + IgnorePattern string `mapstructure:"ignore-pattern"` // Deprecated: this setting has no effect; see IgnoreEnumMembers instead. + CheckingStrategy string `mapstructure:"checking-strategy"` // Deprecated. } type ExhaustiveStructSettings struct { diff --git a/pkg/golinters/exhaustive.go b/pkg/golinters/exhaustive.go index f3a138295e40..bd9921ba7d23 100644 --- a/pkg/golinters/exhaustive.go +++ b/pkg/golinters/exhaustive.go @@ -17,9 +17,11 @@ func NewExhaustive(settings *config.ExhaustiveSettings) *goanalysis.Linter { a.Name: { exhaustive.CheckGeneratedFlag: settings.CheckGenerated, exhaustive.DefaultSignifiesExhaustiveFlag: settings.DefaultSignifiesExhaustive, - exhaustive.IgnorePatternFlag: settings.IgnorePattern, exhaustive.IgnoreEnumMembersFlag: settings.IgnoreEnumMembers, - exhaustive.CheckingStrategyFlag: settings.CheckingStrategy, + exhaustive.PackageScopeOnly: settings.PackageScopeOnly, + + exhaustive.IgnorePatternFlag: settings.IgnorePattern, + exhaustive.CheckingStrategyFlag: settings.CheckingStrategy, }, } }