Skip to content

Commit 247b6c2

Browse files
authored
Add wrapcheck linter (#1407)
* Add failing test * Add wrapcheck linter
1 parent 25fcad6 commit 247b6c2

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ require (
5454
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2
5555
github.com/tetafro/godot v0.4.9
5656
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e
57+
github.com/tomarrell/wrapcheck v0.0.0-20200807122107-df9e8bcb914d
5758
github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa
5859
github.com/ultraware/funlen v0.0.3
5960
github.com/ultraware/whitespace v0.0.4

go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/wrapcheck.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package golinters
2+
3+
import (
4+
"github.com/tomarrell/wrapcheck/wrapcheck"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
const wrapcheckName = "wrapcheck"
11+
12+
func NewWrapcheck() *goanalysis.Linter {
13+
return goanalysis.NewLinter(
14+
wrapcheckName,
15+
wrapcheck.Analyzer.Doc,
16+
[]*analysis.Analyzer{wrapcheck.Analyzer},
17+
nil,
18+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
19+
}

pkg/lint/lintersdb/manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,15 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
307307
WithPresets(linter.PresetStyle).
308308
WithLoadForGoAnalysis().
309309
WithURL("https://github.com/ssgreg/nlreturn"),
310+
linter.NewConfig(golinters.NewWrapcheck()).
311+
WithPresets(linter.PresetStyle).
312+
WithLoadForGoAnalysis().
313+
WithURL("https://github.com/tomarrell/wrapcheck"),
310314
linter.NewConfig(golinters.NewTparallel()).
311315
WithPresets(linter.PresetStyle).
312316
WithLoadForGoAnalysis().
313317
WithURL("https://github.com/moricho/tparallel"),
318+
314319
// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
315320
linter.NewConfig(golinters.NewNoLintLint()).
316321
WithPresets(linter.PresetStyle).

test/testdata/wrapcheck.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//args: -Ewrapcheck
2+
package main
3+
4+
import (
5+
"encoding/json"
6+
)
7+
8+
func main() {
9+
do()
10+
}
11+
12+
func do() error {
13+
_, err := json.Marshal(struct{}{})
14+
if err != nil {
15+
return err // ERROR "error returned from external package is unwrapped"
16+
}
17+
18+
return nil
19+
}

0 commit comments

Comments
 (0)