File tree 4 files changed +74
-5
lines changed
4 files changed +74
-5
lines changed Original file line number Diff line number Diff line change @@ -326,6 +326,16 @@ linters-settings:
326
326
# Check for plain error comparisons.
327
327
# Default: true
328
328
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"
329
339
330
340
exhaustive :
331
341
# Program elements to check for exhaustiveness.
Original file line number Diff line number Diff line change 803
803
"description" : " Check for plain error comparisons" ,
804
804
"type" : " boolean" ,
805
805
"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
+ }
806
836
}
807
837
}
808
838
},
Original file line number Diff line number Diff line change @@ -384,10 +384,17 @@ type ErrChkJSONSettings struct {
384
384
}
385
385
386
386
type 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"`
391
398
}
392
399
393
400
type ExhaustiveSettings struct {
Original file line number Diff line number Diff line change @@ -9,7 +9,21 @@ import (
9
9
)
10
10
11
11
func 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 ... )
13
27
14
28
cfgMap := map [string ]map [string ]any {}
15
29
@@ -30,3 +44,11 @@ func New(cfg *config.ErrorLintSettings) *goanalysis.Linter {
30
44
cfgMap ,
31
45
).WithLoadMode (goanalysis .LoadModeTypesInfo )
32
46
}
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