diff --git a/go.mod b/go.mod index c97f4ae6..2ad84522 100644 --- a/go.mod +++ b/go.mod @@ -54,6 +54,7 @@ require ( github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 github.com/tetafro/godot v0.4.9 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.3 github.com/ultraware/whitespace v0.0.4 diff --git a/go.sum b/go.sum index 446097f1..76c5a665 100644 --- a/go.sum +++ b/go.sum @@ -376,6 +376,8 @@ github.com/tetafro/godot v0.4.9/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/ultraware/funlen v0.0.3 h1:5ylVWm8wsNwH5aWo9438pwvsK0QiqVuUrt9bn7S/iLA= diff --git a/pkg/golinters/wrapcheck.go b/pkg/golinters/wrapcheck.go new file mode 100644 index 00000000..e1592e50 --- /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 502d307d..767ab870 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -307,10 +307,15 @@ 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"), linter.NewConfig(golinters.NewTparallel()). WithPresets(linter.PresetStyle). WithLoadForGoAnalysis(). WithURL("https://github.com/moricho/tparallel"), + // 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). diff --git a/test/testdata/wrapcheck.go b/test/testdata/wrapcheck.go new file mode 100644 index 00000000..96282934 --- /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 +}