Skip to content

Commit

Permalink
build(deps): bump github.com/polyfloyd/go-errorlint from 1.4.8 to 1.5…
Browse files Browse the repository at this point in the history
….1 (#4690)

Co-authored-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
dependabot[bot] and ldez authored May 2, 2024
1 parent 0260ec8 commit 24bcca2
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.

30 changes: 30 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
}
},
Expand Down
15 changes: 11 additions & 4 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 23 additions & 1 deletion pkg/golinters/errorlint/errorlint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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
}

0 comments on commit 24bcca2

Please sign in to comment.