From b0c49a5825b3109eadd8e2f457da05c337dc9633 Mon Sep 17 00:00:00 2001 From: Tom Arrell Date: Fri, 7 Aug 2020 17:06:15 +0200 Subject: [PATCH 1/2] Add failing test --- test/testdata/wrapcheck.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/testdata/wrapcheck.go diff --git a/test/testdata/wrapcheck.go b/test/testdata/wrapcheck.go new file mode 100644 index 000000000000..96282934e28e --- /dev/null +++ b/test/testdata/wrapcheck.go @@ -0,0 +1,19 @@ +//args: -Ewrapcheck +package main + +import ( + "encoding/json" +) + +func main() { + do() +} + +func do() error { + _, err := json.Marshal(struct{}{}) + if err != nil { + return err // ERROR "error returned from external package is unwrapped" + } + + return nil +} From d6f3b0adfb91bc59f34231cd3639bc81d3f20e2c Mon Sep 17 00:00:00 2001 From: Tom Arrell Date: Fri, 2 Oct 2020 11:49:00 +0200 Subject: [PATCH 2/2] Add wrapcheck linter --- go.mod | 1 + go.sum | 2 ++ pkg/golinters/wrapcheck.go | 19 +++++++++++++++++++ pkg/lint/lintersdb/manager.go | 5 +++++ 4 files changed, 27 insertions(+) create mode 100644 pkg/golinters/wrapcheck.go diff --git a/go.mod b/go.mod index 6a9bc93d2b8d..60e1651564d4 100644 --- a/go.mod +++ b/go.mod @@ -53,6 +53,7 @@ require ( github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 github.com/tetafro/godot v0.4.8 github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e + github.com/tomarrell/wrapcheck v0.0.0-20200807122107-df9e8bcb914d github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa github.com/ultraware/funlen v0.0.2 github.com/ultraware/whitespace v0.0.4 diff --git a/go.sum b/go.sum index db3c0958f63c..d713d8e76c6f 100644 --- a/go.sum +++ b/go.sum @@ -379,6 +379,8 @@ github.com/tetafro/godot v0.4.8/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQx github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q= github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tomarrell/wrapcheck v0.0.0-20200807122107-df9e8bcb914d h1:3EZyvNUMsGD1QA8cu0STNn1L7I77rvhf2IhOcHYQhSw= +github.com/tomarrell/wrapcheck v0.0.0-20200807122107-df9e8bcb914d/go.mod h1:yiFB6fFoV7saXirUGfuK+cPtUh4NX/Hf5y2WC2lehu0= github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa h1:RC4maTWLKKwb7p1cnoygsbKIgNlJqSYBeAFON3Ar8As= github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa/go.mod h1:dSUh0FtTP8VhvkL1S+gUR1OKd9ZnSaozuI6r3m6wOig= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= diff --git a/pkg/golinters/wrapcheck.go b/pkg/golinters/wrapcheck.go new file mode 100644 index 000000000000..e1592e50b5bf --- /dev/null +++ b/pkg/golinters/wrapcheck.go @@ -0,0 +1,19 @@ +package golinters + +import ( + "github.com/tomarrell/wrapcheck/wrapcheck" + "golang.org/x/tools/go/analysis" + + "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" +) + +const wrapcheckName = "wrapcheck" + +func NewWrapcheck() *goanalysis.Linter { + return goanalysis.NewLinter( + wrapcheckName, + wrapcheck.Analyzer.Doc, + []*analysis.Analyzer{wrapcheck.Analyzer}, + nil, + ).WithLoadMode(goanalysis.LoadModeTypesInfo) +} diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 7ffaf9c2e229..19fa955a6264 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -305,6 +305,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithPresets(linter.PresetStyle). WithLoadForGoAnalysis(). WithURL("https://github.com/ssgreg/nlreturn"), + linter.NewConfig(golinters.NewWrapcheck()). + WithPresets(linter.PresetStyle). + WithLoadForGoAnalysis(). + WithURL("https://github.com/tomarrell/wrapcheck"), + // nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives linter.NewConfig(golinters.NewNoLintLint()). WithPresets(linter.PresetStyle).