Skip to content

Commit 932adf6

Browse files
committed
review
1 parent 4f5bc60 commit 932adf6

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

.golangci.reference.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,9 @@ linters-settings:
10731073
alias: $1$2
10741074

10751075
interfacebloat:
1076-
interface-len: 10
1076+
# The number of allowed methods for an interface.
1077+
# Default: 10
1078+
len: 5
10771079

10781080
ireturn:
10791081
# ireturn allows using `allow` and `reject` settings at the same time.

pkg/config/linters_settings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ type LintersSettings struct {
151151
Grouper GrouperSettings
152152
Ifshort IfshortSettings
153153
ImportAs ImportAsSettings
154+
InterfaceBloat InterfaceBloatSettings
154155
Ireturn IreturnSettings
155156
Lll LllSettings
156157
MaintIdx MaintIdxSettings
@@ -454,6 +455,10 @@ type ImportAsAlias struct {
454455
Alias string
455456
}
456457

458+
type InterfaceBloatSettings struct {
459+
Len int `mapstructure:"len"`
460+
}
461+
457462
type IreturnSettings struct {
458463
Allow []string `mapstructure:"allow"`
459464
Reject []string `mapstructure:"reject"`

pkg/golinters/interfacebloat.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@ import (
44
"github.com/sashamelentyev/interfacebloat/pkg/analyzer"
55
"golang.org/x/tools/go/analysis"
66

7+
"github.com/golangci/golangci-lint/pkg/config"
78
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
89
)
910

10-
func NewInterfaceBloat() *goanalysis.Linter {
11+
func NewInterfaceBloat(settings *config.InterfaceBloatSettings) *goanalysis.Linter {
1112
a := analyzer.New()
1213

14+
cfgMap := make(map[string]map[string]interface{})
15+
if settings != nil {
16+
cfgMap[a.Name] = map[string]interface{}{
17+
analyzer.InterfaceLenFlag: settings.Len,
18+
}
19+
}
20+
1321
return goanalysis.NewLinter(
1422
a.Name,
1523
a.Doc,
1624
[]*analysis.Analyzer{a},
1725
nil,
18-
)
26+
).WithLoadMode(goanalysis.LoadModeSyntax)
1927
}

pkg/lint/lintersdb/manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
137137
grouperCfg *config.GrouperSettings
138138
ifshortCfg *config.IfshortSettings
139139
importAsCfg *config.ImportAsSettings
140+
interfaceBloatCfg *config.InterfaceBloatSettings
140141
ireturnCfg *config.IreturnSettings
141142
lllCfg *config.LllSettings
142143
maintIdxCfg *config.MaintIdxSettings
@@ -209,6 +210,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
209210
grouperCfg = &m.cfg.LintersSettings.Grouper
210211
ifshortCfg = &m.cfg.LintersSettings.Ifshort
211212
importAsCfg = &m.cfg.LintersSettings.ImportAs
213+
interfaceBloatCfg = &m.cfg.LintersSettings.InterfaceBloat
212214
ireturnCfg = &m.cfg.LintersSettings.Ireturn
213215
lllCfg = &m.cfg.LintersSettings.Lll
214216
maintIdxCfg = &m.cfg.LintersSettings.MaintIdx
@@ -557,9 +559,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
557559
WithPresets(linter.PresetUnused).
558560
WithURL("https://github.com/gordonklaus/ineffassign"),
559561

560-
linter.NewConfig(golinters.NewInterfaceBloat()).
561-
WithSince("v1.48.0").
562-
WithLoadForGoAnalysis().
562+
linter.NewConfig(golinters.NewInterfaceBloat(interfaceBloatCfg)).
563+
WithSince("v1.49.0").
563564
WithPresets(linter.PresetStyle).
564565
WithURL("https://github.com/sashamelentyev/interfacebloat"),
565566

test/testdata/interfacebloat.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//golangcitest:args -Einterfacebloat
22
package testdata
33

4-
type _ interface { // want "length of interface greater than 10"
5-
a()
4+
import "time"
5+
6+
type _ interface { // ERROR "length of interface greater than 10"
7+
a() time.Duration
68
b()
79
c()
810
d()
@@ -16,8 +18,8 @@ type _ interface { // want "length of interface greater than 10"
1618
}
1719

1820
func _() {
19-
var _ interface { // want "length of interface greater than 10"
20-
a()
21+
var _ interface { // ERROR "length of interface greater than 10"
22+
a() time.Duration
2123
b()
2224
c()
2325
d()
@@ -31,8 +33,8 @@ func _() {
3133
}
3234
}
3335

34-
func __() interface { // want "length of interface greater than 10"
35-
a()
36+
func __() interface { // ERROR "length of interface greater than 10"
37+
a() time.Duration
3638
b()
3739
c()
3840
d()

0 commit comments

Comments
 (0)