Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Aug 20, 2022
1 parent 932adf6 commit fba144f
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .golangci.reference.yml
Expand Up @@ -1073,9 +1073,9 @@ linters-settings:
alias: $1$2

interfacebloat:
# The number of allowed methods for an interface.
# The maximum number of methods allowed for an interface.
# Default: 10
len: 5
max: 5

ireturn:
# ireturn allows using `allow` and `reject` settings at the same time.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -74,7 +74,7 @@ require (
github.com/ryancurrah/gomodguard v1.2.4
github.com/ryanrolds/sqlclosecheck v0.3.0
github.com/sanposhiho/wastedassign/v2 v2.0.6
github.com/sashamelentyev/interfacebloat v1.0.0
github.com/sashamelentyev/interfacebloat v1.1.0
github.com/sashamelentyev/usestdlibvars v1.10.0
github.com/securego/gosec/v2 v2.12.0
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
Expand Down
4 changes: 2 additions & 2 deletions go.sum

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

2 changes: 1 addition & 1 deletion pkg/config/linters_settings.go
Expand Up @@ -456,7 +456,7 @@ type ImportAsAlias struct {
}

type InterfaceBloatSettings struct {
Len int `mapstructure:"len"`
Max int `mapstructure:"max"`
}

type IreturnSettings struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/interfacebloat.go
Expand Up @@ -14,7 +14,7 @@ func NewInterfaceBloat(settings *config.InterfaceBloatSettings) *goanalysis.Lint
cfgMap := make(map[string]map[string]interface{})
if settings != nil {
cfgMap[a.Name] = map[string]interface{}{
analyzer.InterfaceLenFlag: settings.Len,
analyzer.InterfaceMaxMethodsFlag: settings.Max,
}
}

Expand Down
154 changes: 115 additions & 39 deletions test/testdata/interfacebloat.go
Expand Up @@ -3,48 +3,124 @@ package testdata

import "time"

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

func _() {
var _ interface { // ERROR "length of interface greater than 10"
a() time.Duration
b()
c()
d()
f()
g()
h()
i()
j()
k()
l()
type InterfaceBloatExample01 interface { // ERROR "the interface has more than 10 methods: 11"
a01() time.Duration
a02()
a03()
a04()
a05()
a06()
a07()
a08()
a09()
a10()
a11()
}

func InterfaceBloatExample02() {
var _ interface { // ERROR "the interface has more than 10 methods: 11"
a01() time.Duration
a02()
a03()
a04()
a05()
a06()
a07()
a08()
a09()
a10()
a11()
}
}

func InterfaceBloatExample03() interface { // ERROR "the interface has more than 10 methods: 11"
a01() time.Duration
a02()
a03()
a04()
a05()
a06()
a07()
a08()
a09()
a10()
a11()
} {
return nil
}

type InterfaceBloatExample04 struct {
Foo interface { // ERROR "the interface has more than 10 methods: 11"
a01() time.Duration
a02()
a03()
a04()
a05()
a06()
a07()
a08()
a09()
a10()
a11()
}
}

type InterfaceBloatSmall01 interface {
a01() time.Duration
a02()
a03()
a04()
a05()
}

type InterfaceBloatSmall02 interface {
a06()
a07()
a08()
a09()
a10()
a11()
}

type InterfaceBloatExample05 interface {
InterfaceBloatSmall01
InterfaceBloatSmall02
}

type InterfaceBloatExample06 interface {
interface { // ERROR "the interface has more than 10 methods: 11"
a01() time.Duration
a02()
a03()
a04()
a05()
a06()
a07()
a08()
a09()
a10()
a11()
}
}

func __() interface { // ERROR "length of interface greater than 10"
a() time.Duration
b()
c()
d()
f()
g()
h()
i()
j()
k()
l()
type InterfaceBloatTypeGeneric interface {
~uint8 | ~uint16 | ~uint32 | ~uint64 | uint |
~int8 | ~int16 | ~int32 | ~int64 | int |
~float32 | ~float64 |
~string
}

func InterfaceBloatExampleNoProblem() interface {
a01() time.Duration
a02()
a03()
a04()
a05()
a06()
a07()
a08()
a09()
a10()
} {
return nil
}

0 comments on commit fba144f

Please sign in to comment.