Skip to content
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
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
}