Skip to content

Commit

Permalink
feat: add interfacebloat
Browse files Browse the repository at this point in the history
  • Loading branch information
sashamelentyev committed Jul 30, 2022
1 parent 886fbd7 commit a061428
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .golangci.reference.yml
Expand Up @@ -1065,6 +1065,9 @@ linters-settings:
- pkg: knative.dev/serving/pkg/apis/(\w+)/(v[\w\d]+)
alias: $1$2

interfacebloat:
interface-len: 10

ireturn:
# ireturn allows using `allow` and `reject` settings at the same time.
# Both settings are lists of the keywords and regular expressions matched to interface or package names.
Expand Down Expand Up @@ -1890,6 +1893,7 @@ linters:
- ifshort
- importas
- ineffassign
- interfacebloat
- interfacer
- ireturn
- lll
Expand Down Expand Up @@ -1991,6 +1995,7 @@ linters:
- ifshort
- importas
- ineffassign
- interfacebloat
- interfacer
- ireturn
- lll
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Expand Up @@ -74,6 +74,7 @@ require (
github.com/ryancurrah/gomodguard v1.2.3
github.com/ryanrolds/sqlclosecheck v0.3.0
github.com/sanposhiho/wastedassign/v2 v2.0.6
github.com/sashamelentyev/interfacebloat v1.0.0
github.com/securego/gosec/v2 v2.12.0
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
github.com/shirou/gopsutil/v3 v3.22.6
Expand Down Expand Up @@ -101,7 +102,7 @@ require (
github.com/yagipy/maintidx v1.0.0
github.com/yeya24/promlinter v0.2.0
gitlab.com/bosi/decorder v0.2.2
golang.org/x/tools v0.1.12-0.20220628192153-7743d1d949f1
golang.org/x/tools v0.1.12
gopkg.in/yaml.v3 v3.0.1
honnef.co/go/tools v0.3.2
mvdan.cc/gofumpt v0.3.1
Expand Down Expand Up @@ -171,8 +172,8 @@ require (
go.uber.org/zap v1.17.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
Expand Down
14 changes: 9 additions & 5 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pkg/golinters/interfacebloat.go
@@ -0,0 +1,19 @@
package golinters

import (
"github.com/sashamelentyev/interfacebloat/pkg/analyzer"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewInterfaceBloat() *goanalysis.Linter {
a := analyzer.New()

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
)
}
6 changes: 6 additions & 0 deletions pkg/lint/lintersdb/manager.go
Expand Up @@ -554,6 +554,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetUnused).
WithURL("https://github.com/gordonklaus/ineffassign"),

linter.NewConfig(golinters.NewInterfaceBloat()).
WithSince("v1.48.0").
WithLoadForGoAnalysis().
WithPresets(linter.PresetStyle).
WithURL("https://github.com/sashamelentyev/interfacebloat"),

linter.NewConfig(golinters.NewInterfacer()).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
Expand Down
48 changes: 48 additions & 0 deletions test/testdata/interfacebloat.go
@@ -0,0 +1,48 @@
//golangcitest:args -Einterfacebloat
package testdata

type _ interface { // want "length of interface greater than 10"
a()
b()
c()
d()
f()
g()
h()
i()
j()
k()
l()
}

func _() {
var _ interface { // want "length of interface greater than 10"
a()
b()
c()
d()
f()
g()
h()
i()
j()
k()
l()
}
}

func __() interface { // want "length of interface greater than 10"
a()
b()
c()
d()
f()
g()
h()
i()
j()
k()
l()
} {
return nil
}

0 comments on commit a061428

Please sign in to comment.