Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Wrapcheck to v2, add configuration #1947

Merged
merged 7 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,18 @@ linters-settings:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature

wrapcheck:
# An array of strings that specify substrings of signatures to ignore.
# If this set, it will override the default set of ignored signatures.
# See https://github.com/tomarrell/wrapcheck#configuration for more information.
ignoreSigs:
ldez marked this conversation as resolved.
Show resolved Hide resolved
- .Errorf(
- errors.New(
- errors.Unwrap(
- .Wrap(
- .Wrapf(
- .WithMessage(

wsl:
# See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for
# documentation of available settings. These are the defaults for
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ require (
github.com/tdakkota/asciicheck v0.0.0-20200416200610-e657995f937b
github.com/tetafro/godot v1.4.6
github.com/timakin/bodyclose v0.0.0-20200424151742-cb6215831a94
github.com/tomarrell/wrapcheck v1.2.0
github.com/tomarrell/wrapcheck/v2 v2.1.0
github.com/tommy-muehle/go-mnd/v2 v2.3.2
github.com/ultraware/funlen v0.0.3
github.com/ultraware/whitespace v0.0.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type LintersSettings struct {
Unused StaticCheckSettings
Varcheck VarCheckSettings
Whitespace WhitespaceSettings
Wrapcheck WrapcheckSettings
WSL WSLSettings

Custom map[string]CustomLinterSettings
Expand Down Expand Up @@ -430,6 +431,10 @@ type WhitespaceSettings struct {
MultiFunc bool `mapstructure:"multi-func"`
}

type WrapcheckSettings struct {
IgnoreSigs []string `mapstructure:"ignoreSigs"`
}

type WSLSettings struct {
StrictAppend bool `mapstructure:"strict-append"`
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
Expand Down
18 changes: 14 additions & 4 deletions pkg/golinters/wrapcheck.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package golinters

import (
"github.com/tomarrell/wrapcheck/wrapcheck"
"github.com/tomarrell/wrapcheck/v2/wrapcheck"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

const wrapcheckName = "wrapcheck"

func NewWrapcheck() *goanalysis.Linter {
func NewWrapcheck(settings *config.WrapcheckSettings) *goanalysis.Linter {
cfg := wrapcheck.NewDefaultConfig()
if settings != nil {
if len(settings.IgnoreSigs) != 0 {
cfg.IgnoreSigs = settings.IgnoreSigs
}
}

a := wrapcheck.NewAnalyzer(cfg)

return goanalysis.NewLinter(
wrapcheckName,
wrapcheck.Analyzer.Doc,
[]*analysis.Analyzer{wrapcheck.Analyzer},
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
4 changes: 3 additions & 1 deletion pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
var staticcheckCfg *config.StaticCheckSettings
var stylecheckCfg *config.StaticCheckSettings
var unusedCfg *config.StaticCheckSettings
var wrapcheckCfg *config.WrapcheckSettings

if m.cfg != nil {
govetCfg = &m.cfg.LintersSettings.Govet
Expand All @@ -137,6 +138,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
staticcheckCfg = &m.cfg.LintersSettings.Staticcheck
stylecheckCfg = &m.cfg.LintersSettings.Stylecheck
unusedCfg = &m.cfg.LintersSettings.Unused
wrapcheckCfg = &m.cfg.LintersSettings.Wrapcheck
}

const megacheckName = "megacheck"
Expand Down Expand Up @@ -411,7 +413,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithSince("v1.30.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/ssgreg/nlreturn"),
linter.NewConfig(golinters.NewWrapcheck()).
linter.NewConfig(golinters.NewWrapcheck(wrapcheckCfg)).
WithSince("v1.32.0").
WithPresets(linter.PresetStyle, linter.PresetError).
WithLoadForGoAnalysis().
Expand Down