From 24bcca2ebd1f26f91d3f2ed124d6660ed8aa6482 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 May 2024 22:43:02 +0200 Subject: [PATCH] build(deps): bump github.com/polyfloyd/go-errorlint from 1.4.8 to 1.5.1 (#4690) Co-authored-by: Fernandez Ludovic --- .golangci.next.reference.yml | 10 ++++++++ go.mod | 2 +- go.sum | 4 ++-- jsonschema/golangci.next.jsonschema.json | 30 ++++++++++++++++++++++++ pkg/config/linters_settings.go | 15 ++++++++---- pkg/golinters/errorlint/errorlint.go | 24 ++++++++++++++++++- 6 files changed, 77 insertions(+), 8 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index e79354fcd545..2995ca5d3423 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -326,6 +326,16 @@ linters-settings: # Check for plain error comparisons. # Default: true comparison: false + # Allowed errors. + # Default: [] + allowed-errors: + - err: "io.EOF" + fun: "example.com/pkg.Read" + # Allowed error "wildcards". + # Default: [] + allowed-errors-wildcard: + - err: "example.com/pkg.ErrMagic" + fun: "example.com/pkg.Magic" exhaustive: # Program elements to check for exhaustiveness. diff --git a/go.mod b/go.mod index 7535d17a3913..ce604ad7b112 100644 --- a/go.mod +++ b/go.mod @@ -84,7 +84,7 @@ require ( github.com/nishanths/predeclared v0.2.2 github.com/nunnatsa/ginkgolinter v0.16.2 github.com/pelletier/go-toml/v2 v2.2.2 - github.com/polyfloyd/go-errorlint v1.4.8 + github.com/polyfloyd/go-errorlint v1.5.1 github.com/quasilyte/go-ruleguard/dsl v0.3.22 github.com/ryancurrah/gomodguard v1.3.2 github.com/ryanrolds/sqlclosecheck v0.5.1 diff --git a/go.sum b/go.sum index fc1fd02468bc..80964b351bbc 100644 --- a/go.sum +++ b/go.sum @@ -424,8 +424,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polyfloyd/go-errorlint v1.4.8 h1:jiEjKDH33ouFktyez7sckv6pHWif9B7SuS8cutDXFHw= -github.com/polyfloyd/go-errorlint v1.4.8/go.mod h1:NNCxFcFjZcw3xNjVdCchERkEM6Oz7wta2XJVxRftwO4= +github.com/polyfloyd/go-errorlint v1.5.1 h1:5gHxDjLyyWij7fhfrjYNNlHsUNQeyx0LFQKUelO3RBo= +github.com/polyfloyd/go-errorlint v1.5.1/go.mod h1:sH1QC1pxxi0fFecsVIzBmxtrgd9IF/SkJpA6wqyKAJs= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index b6a5833c0e02..e7684df3f395 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -803,6 +803,36 @@ "description": "Check for plain error comparisons", "type": "boolean", "default": true + }, + "allowed-errors": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "err": { + "type": "string" + }, + "fun": { + "type": "string" + } + } + } + }, + "allowed-errors-wildcard": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "err": { + "type": "string" + }, + "fun": { + "type": "string" + } + } + } } } }, diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 6f02050a639a..d793ef99711c 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -384,10 +384,17 @@ type ErrChkJSONSettings struct { } type ErrorLintSettings struct { - Errorf bool `mapstructure:"errorf"` - ErrorfMulti bool `mapstructure:"errorf-multi"` - Asserts bool `mapstructure:"asserts"` - Comparison bool `mapstructure:"comparison"` + Errorf bool `mapstructure:"errorf"` + ErrorfMulti bool `mapstructure:"errorf-multi"` + Asserts bool `mapstructure:"asserts"` + Comparison bool `mapstructure:"comparison"` + AllowedErrors []ErrorLintAllowPair `mapstructure:"allowed-errors"` + AllowedErrorsWildcard []ErrorLintAllowPair `mapstructure:"allowed-errors-wildcard"` +} + +type ErrorLintAllowPair struct { + Err string `mapstructure:"err"` + Fun string `mapstructure:"fun"` } type ExhaustiveSettings struct { diff --git a/pkg/golinters/errorlint/errorlint.go b/pkg/golinters/errorlint/errorlint.go index 5eb78f192828..86db8552d04f 100644 --- a/pkg/golinters/errorlint/errorlint.go +++ b/pkg/golinters/errorlint/errorlint.go @@ -9,7 +9,21 @@ import ( ) func New(cfg *config.ErrorLintSettings) *goanalysis.Linter { - a := errorlint.NewAnalyzer() + var opts []errorlint.Option + + if cfg != nil { + ae := toAllowPairs(cfg.AllowedErrors) + if len(ae) > 0 { + opts = append(opts, errorlint.WithAllowedErrors(ae)) + } + + aew := toAllowPairs(cfg.AllowedErrorsWildcard) + if len(aew) > 0 { + opts = append(opts, errorlint.WithAllowedWildcard(aew)) + } + } + + a := errorlint.NewAnalyzer(opts...) cfgMap := map[string]map[string]any{} @@ -30,3 +44,11 @@ func New(cfg *config.ErrorLintSettings) *goanalysis.Linter { cfgMap, ).WithLoadMode(goanalysis.LoadModeTypesInfo) } + +func toAllowPairs(data []config.ErrorLintAllowPair) []errorlint.AllowPair { + var pairs []errorlint.AllowPair + for _, allowedError := range data { + pairs = append(pairs, errorlint.AllowPair(allowedError)) + } + return pairs +}