1
0
mirror of https://github.com/mgechev/revive.git synced 2025-01-08 03:13:27 +02:00

Add tests for the arguments limit

This commit is contained in:
mgechev 2018-02-04 15:10:35 -08:00
parent 8187cdf97d
commit 655402f527
3 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,17 @@
package fixtures
func foo(a, b, c, d int) { // MATCH /maximum number of arguments per function exceeded; max 3 but got 4/
}
func bar(a, b int) {
}
func baz(a string, b int) {
}
func qux(a string, b int, c int, d string, e int64) { // MATCH /maximum number of arguments per function exceeded; max 3 but got 5/
}

View File

@ -48,7 +48,12 @@ type lintArgsNum struct {
func (w lintArgsNum) Visit(n ast.Node) ast.Visitor {
node, ok := n.(*ast.FuncDecl)
if ok {
num := len(node.Type.Params.List)
num := 0
for _, l := range node.Type.Params.List {
for range l.Names {
num++
}
}
if num > w.total {
w.onFailure(lint.Failure{
Confidence: 1,

View File

@ -0,0 +1,14 @@
package test
import (
"testing"
"github.com/mgechev/revive/lint"
"github.com/mgechev/revive/rule"
)
func TestArgumentLimit(t *testing.T) {
testRule(t, "argument-limit", &rule.ArgumentsLimitRule{}, &lint.RuleConfig{
Arguments: []interface{}{int64(3)},
})
}