File tree Expand file tree Collapse file tree 6 files changed +122
-46
lines changed Expand file tree Collapse file tree 6 files changed +122
-46
lines changed Original file line number Diff line number Diff line change @@ -1073,9 +1073,9 @@ linters-settings:
10731073 alias : $1$2
10741074
10751075 interfacebloat :
1076- # The number of allowed methods for an interface.
1076+ # The maximum number of methods allowed for an interface.
10771077 # Default: 10
1078- len : 5
1078+ max : 5
10791079
10801080 ireturn :
10811081 # ireturn allows using `allow` and `reject` settings at the same time.
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ require (
7474 github.com/ryancurrah/gomodguard v1.2.4
7575 github.com/ryanrolds/sqlclosecheck v0.3.0
7676 github.com/sanposhiho/wastedassign/v2 v2.0.6
77- github.com/sashamelentyev/interfacebloat v1.0 .0
77+ github.com/sashamelentyev/interfacebloat v1.1 .0
7878 github.com/sashamelentyev/usestdlibvars v1.10.0
7979 github.com/securego/gosec/v2 v2.12.0
8080 github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
Original file line number Diff line number Diff line change @@ -456,7 +456,7 @@ type ImportAsAlias struct {
456456}
457457
458458type InterfaceBloatSettings struct {
459- Len int `mapstructure:"len "`
459+ Max int `mapstructure:"max "`
460460}
461461
462462type IreturnSettings struct {
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ func NewInterfaceBloat(settings *config.InterfaceBloatSettings) *goanalysis.Lint
1414 cfgMap := make (map [string ]map [string ]interface {})
1515 if settings != nil {
1616 cfgMap [a .Name ] = map [string ]interface {}{
17- analyzer .InterfaceLenFlag : settings .Len ,
17+ analyzer .InterfaceMaxMethodsFlag : settings .Max ,
1818 }
1919 }
2020
Original file line number Diff line number Diff line change @@ -3,48 +3,124 @@ package testdata
33
44import "time"
55
6- type _ interface { // ERROR "length of interface greater than 10"
7- a () time.Duration
8- b ()
9- c ()
10- d ()
11- f ()
12- g ()
13- h ()
14- i ()
15- j ()
16- k ()
17- l ()
18- }
19-
20- func _ () {
21- var _ interface { // ERROR "length of interface greater than 10"
22- a () time.Duration
23- b ()
24- c ()
25- d ()
26- f ()
27- g ()
28- h ()
29- i ()
30- j ()
31- k ()
32- l ()
6+ type InterfaceBloatExample01 interface { // ERROR "the interface has more than 10 methods: 11"
7+ a01 () time.Duration
8+ a02 ()
9+ a03 ()
10+ a04 ()
11+ a05 ()
12+ a06 ()
13+ a07 ()
14+ a08 ()
15+ a09 ()
16+ a10 ()
17+ a11 ()
18+ }
19+
20+ func InterfaceBloatExample02 () {
21+ var _ interface { // ERROR "the interface has more than 10 methods: 11"
22+ a01 () time.Duration
23+ a02 ()
24+ a03 ()
25+ a04 ()
26+ a05 ()
27+ a06 ()
28+ a07 ()
29+ a08 ()
30+ a09 ()
31+ a10 ()
32+ a11 ()
33+ }
34+ }
35+
36+ func InterfaceBloatExample03 () interface { // ERROR "the interface has more than 10 methods: 11"
37+ a01 () time.Duration
38+ a02 ()
39+ a03 ()
40+ a04 ()
41+ a05 ()
42+ a06 ()
43+ a07 ()
44+ a08 ()
45+ a09 ()
46+ a10 ()
47+ a11 ()
48+ } {
49+ return nil
50+ }
51+
52+ type InterfaceBloatExample04 struct {
53+ Foo interface { // ERROR "the interface has more than 10 methods: 11"
54+ a01 () time.Duration
55+ a02 ()
56+ a03 ()
57+ a04 ()
58+ a05 ()
59+ a06 ()
60+ a07 ()
61+ a08 ()
62+ a09 ()
63+ a10 ()
64+ a11 ()
65+ }
66+ }
67+
68+ type InterfaceBloatSmall01 interface {
69+ a01 () time.Duration
70+ a02 ()
71+ a03 ()
72+ a04 ()
73+ a05 ()
74+ }
75+
76+ type InterfaceBloatSmall02 interface {
77+ a06 ()
78+ a07 ()
79+ a08 ()
80+ a09 ()
81+ a10 ()
82+ a11 ()
83+ }
84+
85+ type InterfaceBloatExample05 interface {
86+ InterfaceBloatSmall01
87+ InterfaceBloatSmall02
88+ }
89+
90+ type InterfaceBloatExample06 interface {
91+ interface { // ERROR "the interface has more than 10 methods: 11"
92+ a01 () time.Duration
93+ a02 ()
94+ a03 ()
95+ a04 ()
96+ a05 ()
97+ a06 ()
98+ a07 ()
99+ a08 ()
100+ a09 ()
101+ a10 ()
102+ a11 ()
33103 }
34104}
35105
36- func __ () interface { // ERROR "length of interface greater than 10"
37- a () time.Duration
38- b ()
39- c ()
40- d ()
41- f ()
42- g ()
43- h ()
44- i ()
45- j ()
46- k ()
47- l ()
106+ type InterfaceBloatTypeGeneric interface {
107+ ~ uint8 | ~ uint16 | ~ uint32 | ~ uint64 | uint |
108+ ~ int8 | ~ int16 | ~ int32 | ~ int64 | int |
109+ ~ float32 | ~ float64 |
110+ ~ string
111+ }
112+
113+ func InterfaceBloatExampleNoProblem () interface {
114+ a01 () time.Duration
115+ a02 ()
116+ a03 ()
117+ a04 ()
118+ a05 ()
119+ a06 ()
120+ a07 ()
121+ a08 ()
122+ a09 ()
123+ a10 ()
48124} {
49125 return nil
50126}
You can’t perform that action at this time.
0 commit comments