Skip to content

Commit fd25941

Browse files
committed
Add wrapcheck linter config
1 parent 12ed5fa commit fd25941

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

.golangci.example.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,15 @@ linters-settings:
550550
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
551551
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
552552

553+
wrapcheck:
554+
ignoreSigs:
555+
- .Errorf(
556+
- errors.New(
557+
- errors.Unwrap(
558+
- .Wrap(
559+
- .Wrapf(
560+
- .WithMessage(
561+
553562
wsl:
554563
# See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for
555564
# documentation of available settings. These are the defaults for

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ require (
7575
github.com/tdakkota/asciicheck v0.0.0-20200416200610-e657995f937b
7676
github.com/tetafro/godot v1.4.6
7777
github.com/timakin/bodyclose v0.0.0-20200424151742-cb6215831a94
78-
github.com/tomarrell/wrapcheck v1.2.0
78+
github.com/tomarrell/wrapcheck/v2 v2.1.0
7979
github.com/tommy-muehle/go-mnd/v2 v2.3.2
8080
github.com/ultraware/funlen v0.0.3
8181
github.com/ultraware/whitespace v0.0.4

go.sum

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

pkg/config/linters_settings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ type LintersSettings struct {
130130
Unused StaticCheckSettings
131131
Varcheck VarCheckSettings
132132
Whitespace WhitespaceSettings
133+
Wrapcheck WrapcheckSettings
133134
WSL WSLSettings
134135

135136
Custom map[string]CustomLinterSettings
@@ -430,6 +431,10 @@ type WhitespaceSettings struct {
430431
MultiFunc bool `mapstructure:"multi-func"`
431432
}
432433

434+
type WrapcheckSettings struct {
435+
IgnoreSigs []string `mapstructure:"ignoreSigs"`
436+
}
437+
433438
type WSLSettings struct {
434439
StrictAppend bool `mapstructure:"strict-append"`
435440
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`

pkg/golinters/wrapcheck.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
package golinters
22

33
import (
4-
"github.com/tomarrell/wrapcheck/wrapcheck"
4+
"github.com/tomarrell/wrapcheck/v2/wrapcheck"
55
"golang.org/x/tools/go/analysis"
66

7+
"github.com/golangci/golangci-lint/pkg/config"
78
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
89
)
910

1011
const wrapcheckName = "wrapcheck"
1112

12-
func NewWrapcheck() *goanalysis.Linter {
13+
func NewWrapcheck(cfg config.WrapcheckSettings) *goanalysis.Linter {
14+
c := wrapcheck.NewDefaultConfig()
15+
c.IgnoreSigs = cfg.IgnoreSigs
16+
17+
a := wrapcheck.NewAnalyzer(c)
18+
1319
return goanalysis.NewLinter(
1420
wrapcheckName,
15-
wrapcheck.Analyzer.Doc,
16-
[]*analysis.Analyzer{wrapcheck.Analyzer},
21+
a.Doc,
22+
[]*analysis.Analyzer{a},
1723
nil,
1824
).WithLoadMode(goanalysis.LoadModeTypesInfo)
1925
}

pkg/lint/lintersdb/manager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
117117
var staticcheckCfg *config.StaticCheckSettings
118118
var stylecheckCfg *config.StaticCheckSettings
119119
var unusedCfg *config.StaticCheckSettings
120+
var wrapcheckCfg *config.WrapcheckSettings
120121

121122
if m.cfg != nil {
122123
govetCfg = &m.cfg.LintersSettings.Govet
@@ -137,6 +138,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
137138
staticcheckCfg = &m.cfg.LintersSettings.Staticcheck
138139
stylecheckCfg = &m.cfg.LintersSettings.Stylecheck
139140
unusedCfg = &m.cfg.LintersSettings.Unused
141+
wrapcheckCfg = &m.cfg.LintersSettings.Wrapcheck
140142
}
141143

142144
const megacheckName = "megacheck"
@@ -411,7 +413,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
411413
WithSince("v1.30.0").
412414
WithPresets(linter.PresetStyle).
413415
WithURL("https://github.com/ssgreg/nlreturn"),
414-
linter.NewConfig(golinters.NewWrapcheck()).
416+
linter.NewConfig(golinters.NewWrapcheck(wrapcheckCfg)).
415417
WithSince("v1.32.0").
416418
WithPresets(linter.PresetStyle, linter.PresetError).
417419
WithLoadForGoAnalysis().

0 commit comments

Comments
 (0)