-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Fernandez Ludovic <[email protected]>
- Loading branch information
1 parent
1bb23af
commit 63b2fe0
Showing
7 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package golinters | ||
|
||
import ( | ||
"github.com/sashamelentyev/interfacebloat/pkg/analyzer" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
) | ||
|
||
func NewInterfaceBloat(settings *config.InterfaceBloatSettings) *goanalysis.Linter { | ||
a := analyzer.New() | ||
|
||
cfgMap := make(map[string]map[string]interface{}) | ||
if settings != nil { | ||
cfgMap[a.Name] = map[string]interface{}{ | ||
analyzer.InterfaceMaxMethodsFlag: settings.Max, | ||
} | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
a.Name, | ||
a.Doc, | ||
[]*analysis.Analyzer{a}, | ||
nil, | ||
).WithLoadMode(goanalysis.LoadModeSyntax) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
//golangcitest:args -Einterfacebloat | ||
package testdata | ||
|
||
import "time" | ||
|
||
type InterfaceBloatExample01 interface { // want "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 { // want "the interface has more than 10 methods: 11" | ||
a01() time.Duration | ||
a02() | ||
a03() | ||
a04() | ||
a05() | ||
a06() | ||
a07() | ||
a08() | ||
a09() | ||
a10() | ||
a11() | ||
} | ||
} | ||
|
||
func InterfaceBloatExample03() interface { // want "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 { // want "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 { // want "the interface has more than 10 methods: 11" | ||
a01() time.Duration | ||
a02() | ||
a03() | ||
a04() | ||
a05() | ||
a06() | ||
a07() | ||
a08() | ||
a09() | ||
a10() | ||
a11() | ||
} | ||
} | ||
|
||
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 | ||
} |