File tree 6 files changed +122
-46
lines changed
6 files changed +122
-46
lines changed Original file line number Diff line number Diff line change @@ -1073,9 +1073,9 @@ linters-settings:
1073
1073
alias : $1$2
1074
1074
1075
1075
interfacebloat :
1076
- # The number of allowed methods for an interface.
1076
+ # The maximum number of methods allowed for an interface.
1077
1077
# Default: 10
1078
- len : 5
1078
+ max : 5
1079
1079
1080
1080
ireturn :
1081
1081
# 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 (
74
74
github.com/ryancurrah/gomodguard v1.2.4
75
75
github.com/ryanrolds/sqlclosecheck v0.3.0
76
76
github.com/sanposhiho/wastedassign/v2 v2.0.6
77
- github.com/sashamelentyev/interfacebloat v1.0 .0
77
+ github.com/sashamelentyev/interfacebloat v1.1 .0
78
78
github.com/sashamelentyev/usestdlibvars v1.10.0
79
79
github.com/securego/gosec/v2 v2.12.0
80
80
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 {
456
456
}
457
457
458
458
type InterfaceBloatSettings struct {
459
- Len int `mapstructure:"len "`
459
+ Max int `mapstructure:"max "`
460
460
}
461
461
462
462
type IreturnSettings struct {
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ func NewInterfaceBloat(settings *config.InterfaceBloatSettings) *goanalysis.Lint
14
14
cfgMap := make (map [string ]map [string ]interface {})
15
15
if settings != nil {
16
16
cfgMap [a .Name ] = map [string ]interface {}{
17
- analyzer .InterfaceLenFlag : settings .Len ,
17
+ analyzer .InterfaceMaxMethodsFlag : settings .Max ,
18
18
}
19
19
}
20
20
Original file line number Diff line number Diff line change @@ -3,48 +3,124 @@ package testdata
3
3
4
4
import "time"
5
5
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 ()
33
103
}
34
104
}
35
105
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 ()
48
124
} {
49
125
return nil
50
126
}
You can’t perform that action at this time.
0 commit comments