Skip to content

Commit 47b91f1

Browse files
sashamelentyevldez
authored andcommitted
feat: add interfacebloat
1 parent d286cb9 commit 47b91f1

File tree

6 files changed

+81
-0
lines changed

6 files changed

+81
-0
lines changed

.golangci.reference.yml

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

1075+
interfacebloat:
1076+
interface-len: 10
1077+
10751078
ireturn:
10761079
# ireturn allows using `allow` and `reject` settings at the same time.
10771080
# Both settings are lists of the keywords and regular expressions matched to interface or package names.
@@ -1921,6 +1924,7 @@ linters:
19211924
- ifshort
19221925
- importas
19231926
- ineffassign
1927+
- interfacebloat
19241928
- interfacer
19251929
- ireturn
19261930
- lll
@@ -2023,6 +2027,7 @@ linters:
20232027
- ifshort
20242028
- importas
20252029
- ineffassign
2030+
- interfacebloat
20262031
- interfacer
20272032
- ireturn
20282033
- lll

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +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
7778
github.com/sashamelentyev/usestdlibvars v1.10.0
7879
github.com/securego/gosec/v2 v2.12.0
7980
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c

go.sum

Lines changed: 2 additions & 0 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
@@ -557,6 +557,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
557557
WithPresets(linter.PresetUnused).
558558
WithURL("https://github.com/gordonklaus/ineffassign"),
559559

560+
linter.NewConfig(golinters.NewInterfaceBloat()).
561+
WithSince("v1.48.0").
562+
WithLoadForGoAnalysis().
563+
WithPresets(linter.PresetStyle).
564+
WithURL("https://github.com/sashamelentyev/interfacebloat"),
565+
560566
linter.NewConfig(golinters.NewInterfacer()).
561567
WithSince("v1.0.0").
562568
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)