File tree Expand file tree Collapse file tree 6 files changed +77
-8
lines changed Expand file tree Collapse file tree 6 files changed +77
-8
lines changed Original file line number Diff line number Diff line change @@ -326,6 +326,16 @@ linters-settings:
326326 # Check for plain error comparisons.
327327 # Default: true
328328 comparison : false
329+ # Allowed errors.
330+ # Default: []
331+ allowed-errors :
332+ - err : " io.EOF"
333+ fun : " example.com/pkg.Read"
334+ # Allowed error "wildcards".
335+ # Default: []
336+ allowed-errors-wildcard :
337+ - err : " example.com/pkg.ErrMagic"
338+ fun : " example.com/pkg.Magic"
329339
330340 exhaustive :
331341 # Program elements to check for exhaustiveness.
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ require (
8484 github.com/nishanths/predeclared v0.2.2
8585 github.com/nunnatsa/ginkgolinter v0.16.2
8686 github.com/pelletier/go-toml/v2 v2.2.2
87- github.com/polyfloyd/go-errorlint v1.4.8
87+ github.com/polyfloyd/go-errorlint v1.5.1
8888 github.com/quasilyte/go-ruleguard/dsl v0.3.22
8989 github.com/ryancurrah/gomodguard v1.3.2
9090 github.com/ryanrolds/sqlclosecheck v0.5.1
Original file line number Diff line number Diff line change 803803 "description" : " Check for plain error comparisons" ,
804804 "type" : " boolean" ,
805805 "default" : true
806+ },
807+ "allowed-errors" : {
808+ "type" : " array" ,
809+ "items" : {
810+ "type" : " object" ,
811+ "additionalProperties" : false ,
812+ "properties" : {
813+ "err" : {
814+ "type" : " string"
815+ },
816+ "fun" : {
817+ "type" : " string"
818+ }
819+ }
820+ }
821+ },
822+ "allowed-errors-wildcard" : {
823+ "type" : " array" ,
824+ "items" : {
825+ "type" : " object" ,
826+ "additionalProperties" : false ,
827+ "properties" : {
828+ "err" : {
829+ "type" : " string"
830+ },
831+ "fun" : {
832+ "type" : " string"
833+ }
834+ }
835+ }
806836 }
807837 }
808838 },
Original file line number Diff line number Diff line change @@ -384,10 +384,17 @@ type ErrChkJSONSettings struct {
384384}
385385
386386type ErrorLintSettings struct {
387- Errorf bool `mapstructure:"errorf"`
388- ErrorfMulti bool `mapstructure:"errorf-multi"`
389- Asserts bool `mapstructure:"asserts"`
390- Comparison bool `mapstructure:"comparison"`
387+ Errorf bool `mapstructure:"errorf"`
388+ ErrorfMulti bool `mapstructure:"errorf-multi"`
389+ Asserts bool `mapstructure:"asserts"`
390+ Comparison bool `mapstructure:"comparison"`
391+ AllowedErrors []ErrorLintAllowPair `mapstructure:"allowed-errors"`
392+ AllowedErrorsWildcard []ErrorLintAllowPair `mapstructure:"allowed-errors-wildcard"`
393+ }
394+
395+ type ErrorLintAllowPair struct {
396+ Err string `mapstructure:"err"`
397+ Fun string `mapstructure:"fun"`
391398}
392399
393400type ExhaustiveSettings struct {
Original file line number Diff line number Diff line change @@ -9,7 +9,21 @@ import (
99)
1010
1111func New (cfg * config.ErrorLintSettings ) * goanalysis.Linter {
12- a := errorlint .NewAnalyzer ()
12+ var opts []errorlint.Option
13+
14+ if cfg != nil {
15+ ae := toAllowPairs (cfg .AllowedErrors )
16+ if len (ae ) > 0 {
17+ opts = append (opts , errorlint .WithAllowedErrors (ae ))
18+ }
19+
20+ aew := toAllowPairs (cfg .AllowedErrorsWildcard )
21+ if len (aew ) > 0 {
22+ opts = append (opts , errorlint .WithAllowedWildcard (aew ))
23+ }
24+ }
25+
26+ a := errorlint .NewAnalyzer (opts ... )
1327
1428 cfgMap := map [string ]map [string ]any {}
1529
@@ -30,3 +44,11 @@ func New(cfg *config.ErrorLintSettings) *goanalysis.Linter {
3044 cfgMap ,
3145 ).WithLoadMode (goanalysis .LoadModeTypesInfo )
3246}
47+
48+ func toAllowPairs (data []config.ErrorLintAllowPair ) []errorlint.AllowPair {
49+ var pairs []errorlint.AllowPair
50+ for _ , allowedError := range data {
51+ pairs = append (pairs , errorlint .AllowPair (allowedError ))
52+ }
53+ return pairs
54+ }
You can’t perform that action at this time.
0 commit comments