Update Wrapcheck to v2, add configuration (#1947)

This commit is contained in:
Tom Arrell 2021-05-01 00:13:51 +02:00 committed by GitHub
parent 12ed5facc9
commit 92fda268b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 8 deletions

View File

@ -550,6 +550,18 @@ linters-settings:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement 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 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:
- .Errorf(
- errors.New(
- errors.Unwrap(
- .Wrap(
- .Wrapf(
- .WithMessage(
wsl: wsl:
# See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for # See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for
# documentation of available settings. These are the defaults for # documentation of available settings. These are the defaults for

2
go.mod
View File

@ -75,7 +75,7 @@ require (
github.com/tdakkota/asciicheck v0.0.0-20200416200610-e657995f937b github.com/tdakkota/asciicheck v0.0.0-20200416200610-e657995f937b
github.com/tetafro/godot v1.4.6 github.com/tetafro/godot v1.4.6
github.com/timakin/bodyclose v0.0.0-20200424151742-cb6215831a94 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/tommy-muehle/go-mnd/v2 v2.3.2
github.com/ultraware/funlen v0.0.3 github.com/ultraware/funlen v0.0.3
github.com/ultraware/whitespace v0.0.4 github.com/ultraware/whitespace v0.0.4

4
go.sum generated
View File

@ -620,8 +620,8 @@ github.com/tklauser/numcpus v0.2.1/go.mod h1:9aU+wOc6WjUIZEwWMP62PL/41d65P+iks1g
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tomarrell/wrapcheck v1.2.0 h1:N1PWGT8l+6jZVTcm00kGjx9IEA8oDMSjipqY73ye5c0= github.com/tomarrell/wrapcheck/v2 v2.1.0 h1:LTzwrYlgBUwi9JldazhbJN84fN9nS2UNGrZIo2syqxE=
github.com/tomarrell/wrapcheck v1.2.0/go.mod h1:Bd3i1FaEKe3XmcPoHhNQ+HM0S8P6eIXoQIoGj/ndJkU= github.com/tomarrell/wrapcheck/v2 v2.1.0/go.mod h1:crK5eI4RGSUrb9duDTQ5GqcukbKZvi85vX6nbhsBAeI=
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4= github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4=
github.com/tommy-muehle/go-mnd/v2 v2.3.2 h1:SLkFtxVVkoypCu6eTERr5U2IC3Kce/zOhA4IyNesPV4= github.com/tommy-muehle/go-mnd/v2 v2.3.2 h1:SLkFtxVVkoypCu6eTERr5U2IC3Kce/zOhA4IyNesPV4=
github.com/tommy-muehle/go-mnd/v2 v2.3.2/go.mod h1:WsUAkMJMYww6l/ufffCD3m+P7LEvr8TnZn9lwVDlgzw= github.com/tommy-muehle/go-mnd/v2 v2.3.2/go.mod h1:WsUAkMJMYww6l/ufffCD3m+P7LEvr8TnZn9lwVDlgzw=

View File

@ -130,6 +130,7 @@ type LintersSettings struct {
Unused StaticCheckSettings Unused StaticCheckSettings
Varcheck VarCheckSettings Varcheck VarCheckSettings
Whitespace WhitespaceSettings Whitespace WhitespaceSettings
Wrapcheck WrapcheckSettings
WSL WSLSettings WSL WSLSettings
Custom map[string]CustomLinterSettings Custom map[string]CustomLinterSettings
@ -430,6 +431,10 @@ type WhitespaceSettings struct {
MultiFunc bool `mapstructure:"multi-func"` MultiFunc bool `mapstructure:"multi-func"`
} }
type WrapcheckSettings struct {
IgnoreSigs []string `mapstructure:"ignoreSigs"`
}
type WSLSettings struct { type WSLSettings struct {
StrictAppend bool `mapstructure:"strict-append"` StrictAppend bool `mapstructure:"strict-append"`
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"` AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`

View File

@ -1,19 +1,29 @@
package golinters package golinters
import ( import (
"github.com/tomarrell/wrapcheck/wrapcheck" "github.com/tomarrell/wrapcheck/v2/wrapcheck"
"golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis"
"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" "github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
) )
const wrapcheckName = "wrapcheck" 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( return goanalysis.NewLinter(
wrapcheckName, wrapcheckName,
wrapcheck.Analyzer.Doc, a.Doc,
[]*analysis.Analyzer{wrapcheck.Analyzer}, []*analysis.Analyzer{a},
nil, nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo) ).WithLoadMode(goanalysis.LoadModeTypesInfo)
} }

View File

@ -117,6 +117,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
var staticcheckCfg *config.StaticCheckSettings var staticcheckCfg *config.StaticCheckSettings
var stylecheckCfg *config.StaticCheckSettings var stylecheckCfg *config.StaticCheckSettings
var unusedCfg *config.StaticCheckSettings var unusedCfg *config.StaticCheckSettings
var wrapcheckCfg *config.WrapcheckSettings
if m.cfg != nil { if m.cfg != nil {
govetCfg = &m.cfg.LintersSettings.Govet govetCfg = &m.cfg.LintersSettings.Govet
@ -137,6 +138,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
staticcheckCfg = &m.cfg.LintersSettings.Staticcheck staticcheckCfg = &m.cfg.LintersSettings.Staticcheck
stylecheckCfg = &m.cfg.LintersSettings.Stylecheck stylecheckCfg = &m.cfg.LintersSettings.Stylecheck
unusedCfg = &m.cfg.LintersSettings.Unused unusedCfg = &m.cfg.LintersSettings.Unused
wrapcheckCfg = &m.cfg.LintersSettings.Wrapcheck
} }
const megacheckName = "megacheck" const megacheckName = "megacheck"
@ -411,7 +413,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithSince("v1.30.0"). WithSince("v1.30.0").
WithPresets(linter.PresetStyle). WithPresets(linter.PresetStyle).
WithURL("https://github.com/ssgreg/nlreturn"), WithURL("https://github.com/ssgreg/nlreturn"),
linter.NewConfig(golinters.NewWrapcheck()). linter.NewConfig(golinters.NewWrapcheck(wrapcheckCfg)).
WithSince("v1.32.0"). WithSince("v1.32.0").
WithPresets(linter.PresetStyle, linter.PresetError). WithPresets(linter.PresetStyle, linter.PresetError).
WithLoadForGoAnalysis(). WithLoadForGoAnalysis().