From 58234f055cd8a4ba71ce6dafb95d7fa665bc8d39 Mon Sep 17 00:00:00 2001 From: nishanths Date: Wed, 14 Oct 2020 11:49:06 +0530 Subject: [PATCH] update exhaustive to latest; use version in go.mod (#1449) * update exhaustive to latest * wip * update dep * update flag name * use versioned dep * add tests * unused file * no need config file * add vars to test * test comment * remove default settings --- .golangci.example.yml | 12 ++++++---- .golangci.yml | 2 -- go.mod | 4 ++-- go.sum | 7 +++--- pkg/config/config.go | 2 ++ pkg/golinters/exhaustive.go | 1 + ...{exhaustive.yml => exhaustive_default.yml} | 0 test/testdata/exhaustive_default.go | 2 +- test/testdata/exhaustive_generated.go | 23 +++++++++++++++++++ 9 files changed, 40 insertions(+), 13 deletions(-) rename test/testdata/configs/{exhaustive.yml => exhaustive_default.yml} (100%) create mode 100644 test/testdata/exhaustive_generated.go diff --git a/.golangci.example.yml b/.golangci.example.yml index 61190bfe19e4..5fd1432e9dad 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -102,6 +102,8 @@ linters-settings: # see https://github.com/kisielk/errcheck#excluding-functions for details exclude: /path/to/file.txt exhaustive: + # check switch statements in generated files also + check-generated: false # indicates that switch statements are to be considered exhaustive if a # 'default' case is present, even if all enum members aren't listed in the # switch @@ -432,22 +434,22 @@ issues: severity: # Default value is empty string. - # Set the default severity for issues. If severity rules are defined and the issues - # do not match or no severity is provided to the rule this will be the default - # severity applied. Severities should match the supported severity names of the + # Set the default severity for issues. If severity rules are defined and the issues + # do not match or no severity is provided to the rule this will be the default + # severity applied. Severities should match the supported severity names of the # selected out format. # - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity # - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#severity # - Github: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message default-severity: error - # The default value is false. + # The default value is false. # If set to true severity-rules regular expressions become case sensitive. case-sensitive: false # Default value is empty list. # When a list of severity rules are provided, severity information will be added to lint - # issues. Severity rules have the same filtering capability as exclude rules except you + # issues. Severity rules have the same filtering capability as exclude rules except you # are allowed to specify one matcher per severity rule. # Only affects out formats that support setting severity information. rules: diff --git a/.golangci.yml b/.golangci.yml index 5e9e1e7c2cb1..012255c281b4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,8 +9,6 @@ linters-settings: - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" dupl: threshold: 100 - exhaustive: - default-signifies-exhaustive: false funlen: lines: 100 statements: 50 diff --git a/go.mod b/go.mod index ba055a9a4133..3181521932db 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( github.com/mitchellh/go-ps v1.0.0 github.com/moricho/tparallel v0.2.1 github.com/nakabonne/nestif v0.3.0 - github.com/nishanths/exhaustive v0.0.0-20200811152831-6cf413ae40e0 + github.com/nishanths/exhaustive v0.1.0 github.com/pkg/errors v0.9.1 github.com/polyfloyd/go-errorlint v0.0.0-20201006195004-351e25ade6e3 github.com/ryancurrah/gomodguard v1.1.0 @@ -62,7 +62,7 @@ require ( github.com/ultraware/whitespace v0.0.4 github.com/uudashr/gocognit v1.0.1 github.com/valyala/quicktemplate v1.6.3 - golang.org/x/tools v0.0.0-20201001104356-43ebab892c4c + golang.org/x/tools v0.0.0-20201011145850-ed2f50202694 gopkg.in/yaml.v2 v2.3.0 honnef.co/go/tools v0.0.1-2020.1.6 mvdan.cc/gofumpt v0.0.0-20200802201014-ab5a8192947d diff --git a/go.sum b/go.sum index 6750f42d0eae..20c84de10a36 100644 --- a/go.sum +++ b/go.sum @@ -272,8 +272,8 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d h1:AREM5mwr4u1 github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU= 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.0.0-20200811152831-6cf413ae40e0 h1:eMV1t2NQRc3r1k3guWiv/zEeqZZP6kPvpUfy6byfL1g= -github.com/nishanths/exhaustive v0.0.0-20200811152831-6cf413ae40e0/go.mod h1:wBEpHwM2OdmeNpdCvRPUlkEbBuaFmcK4Wv8Q7FuGW3c= +github.com/nishanths/exhaustive v0.1.0 h1:kVlMw8h2LHPMGUVqUj6230oQjjTMFjwcZrnkhXzFfl8= +github.com/nishanths/exhaustive v0.1.0/go.mod h1:S1j9110vxV1ECdCudXRkeMnFQ/DQk9ajLT0Uf2MYZQQ= github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= @@ -538,7 +538,6 @@ golang.org/x/tools v0.0.0-20200410194907-79a7a3126eef/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200414032229-332987a829c3/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200426102838-f3a5411a4c3b/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200519015757-0d0afa43d58a/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200624225443-88f3c62a19ff/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200625211823-6506e20df31f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200701041122-1837592efa10/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -548,6 +547,8 @@ golang.org/x/tools v0.0.0-20200812195022-5ae4c3c160a0/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200831203904-5a2aa26beb65/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= golang.org/x/tools v0.0.0-20201001104356-43ebab892c4c h1:9BSeO6440XJVa2mxIcRAndAol4g4g2KflCVGcHx9Yu8= golang.org/x/tools v0.0.0-20201001104356-43ebab892c4c/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= +golang.org/x/tools v0.0.0-20201011145850-ed2f50202694 h1:BANdcOVw3KTuUiyfDp7wrzCpkCe8UP3lowugJngxBTg= +golang.org/x/tools v0.0.0-20201011145850-ed2f50202694/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/config/config.go b/pkg/config/config.go index 3f42c6049e94..5b73a36de349 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -354,6 +354,7 @@ type NestifSettings struct { } type ExhaustiveSettings struct { + CheckGenerated bool `mapstructure:"check-generated"` DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"` } @@ -416,6 +417,7 @@ var defaultLintersSettings = LintersSettings{ MinComplexity: 5, }, Exhaustive: ExhaustiveSettings{ + CheckGenerated: false, DefaultSignifiesExhaustive: false, }, Gofumpt: GofumptSettings{ diff --git a/pkg/golinters/exhaustive.go b/pkg/golinters/exhaustive.go index cae37ecc61d3..85534d42cda8 100644 --- a/pkg/golinters/exhaustive.go +++ b/pkg/golinters/exhaustive.go @@ -15,6 +15,7 @@ func NewExhaustive(settings *config.ExhaustiveSettings) *goanalysis.Linter { if settings != nil { cfg = map[string]map[string]interface{}{ a.Name: { + exhaustive.CheckGeneratedFlag: settings.CheckGenerated, exhaustive.DefaultSignifiesExhaustiveFlag: settings.DefaultSignifiesExhaustive, }, } diff --git a/test/testdata/configs/exhaustive.yml b/test/testdata/configs/exhaustive_default.yml similarity index 100% rename from test/testdata/configs/exhaustive.yml rename to test/testdata/configs/exhaustive_default.yml diff --git a/test/testdata/exhaustive_default.go b/test/testdata/exhaustive_default.go index 36c1dee6ed03..1dc2637fd198 100644 --- a/test/testdata/exhaustive_default.go +++ b/test/testdata/exhaustive_default.go @@ -1,5 +1,5 @@ //args: -Eexhaustive -//config_path: testdata/configs/exhaustive.yml +//config_path: testdata/configs/exhaustive_default.yml package testdata type Direction int diff --git a/test/testdata/exhaustive_generated.go b/test/testdata/exhaustive_generated.go new file mode 100644 index 000000000000..ab9a351d6192 --- /dev/null +++ b/test/testdata/exhaustive_generated.go @@ -0,0 +1,23 @@ +//args: -Eexhaustive +package testdata + +// Code generated by some program. DO NOT EDIT. + +// Should not report missing cases in the switch statement below, because this +// is a generated file as indicated by the above comment +// (golang.org/s/generatedcode), and check-generated setting is false. + +type Direction int + +const ( + North Direction = iota + East + South + West +) + +func processDirectionGenerated(d Direction) { + switch d { + case North, South: + } +}