Skip to content

Commit a061428

Browse files
feat: add interfacebloat
1 parent 886fbd7 commit a061428

File tree

6 files changed

+91
-8
lines changed

6 files changed

+91
-8
lines changed

.golangci.reference.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,9 @@ linters-settings:
10651065
- pkg: knative.dev/serving/pkg/apis/(\w+)/(v[\w\d]+)
10661066
alias: $1$2
10671067

1068+
interfacebloat:
1069+
interface-len: 10
1070+
10681071
ireturn:
10691072
# ireturn allows using `allow` and `reject` settings at the same time.
10701073
# Both settings are lists of the keywords and regular expressions matched to interface or package names.
@@ -1890,6 +1893,7 @@ linters:
18901893
- ifshort
18911894
- importas
18921895
- ineffassign
1896+
- interfacebloat
18931897
- interfacer
18941898
- ireturn
18951899
- lll
@@ -1991,6 +1995,7 @@ linters:
19911995
- ifshort
19921996
- importas
19931997
- ineffassign
1998+
- interfacebloat
19941999
- interfacer
19952000
- ireturn
19962001
- lll

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ require (
7474
github.com/ryancurrah/gomodguard v1.2.3
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
7778
github.com/securego/gosec/v2 v2.12.0
7879
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
7980
github.com/shirou/gopsutil/v3 v3.22.6
@@ -101,7 +102,7 @@ require (
101102
github.com/yagipy/maintidx v1.0.0
102103
github.com/yeya24/promlinter v0.2.0
103104
gitlab.com/bosi/decorder v0.2.2
104-
golang.org/x/tools v0.1.12-0.20220628192153-7743d1d949f1
105+
golang.org/x/tools v0.1.12
105106
gopkg.in/yaml.v3 v3.0.1
106107
honnef.co/go/tools v0.3.2
107108
mvdan.cc/gofumpt v0.3.1
@@ -171,8 +172,8 @@ require (
171172
go.uber.org/zap v1.17.0 // indirect
172173
golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d // indirect
173174
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
174-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
175-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
175+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
176+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
176177
golang.org/x/text v0.3.7 // indirect
177178
google.golang.org/protobuf v1.28.0 // indirect
178179
gopkg.in/ini.v1 v1.66.6 // indirect

go.sum

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/interfacebloat.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package golinters
2+
3+
import (
4+
"github.com/sashamelentyev/interfacebloat/pkg/analyzer"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
func NewInterfaceBloat() *goanalysis.Linter {
11+
a := analyzer.New()
12+
13+
return goanalysis.NewLinter(
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
17+
nil,
18+
)
19+
}

pkg/lint/lintersdb/manager.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
554554
WithPresets(linter.PresetUnused).
555555
WithURL("https://github.com/gordonklaus/ineffassign"),
556556

557+
linter.NewConfig(golinters.NewInterfaceBloat()).
558+
WithSince("v1.48.0").
559+
WithLoadForGoAnalysis().
560+
WithPresets(linter.PresetStyle).
561+
WithURL("https://github.com/sashamelentyev/interfacebloat"),
562+
557563
linter.NewConfig(golinters.NewInterfacer()).
558564
WithSince("v1.0.0").
559565
WithLoadForGoAnalysis().

test/testdata/interfacebloat.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//golangcitest:args -Einterfacebloat
2+
package testdata
3+
4+
type _ interface { // want "length of interface greater than 10"
5+
a()
6+
b()
7+
c()
8+
d()
9+
f()
10+
g()
11+
h()
12+
i()
13+
j()
14+
k()
15+
l()
16+
}
17+
18+
func _() {
19+
var _ interface { // want "length of interface greater than 10"
20+
a()
21+
b()
22+
c()
23+
d()
24+
f()
25+
g()
26+
h()
27+
i()
28+
j()
29+
k()
30+
l()
31+
}
32+
}
33+
34+
func __() interface { // want "length of interface greater than 10"
35+
a()
36+
b()
37+
c()
38+
d()
39+
f()
40+
g()
41+
h()
42+
i()
43+
j()
44+
k()
45+
l()
46+
} {
47+
return nil
48+
}

0 commit comments

Comments
 (0)