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:
parent
8187cdf97d
commit
655402f527
17
fixtures/argument-limit.go
Normal file
17
fixtures/argument-limit.go
Normal 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/
|
||||
|
||||
}
|
@ -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,
|
||||
|
14
test/argument-limit_test.go
Normal file
14
test/argument-limit_test.go
Normal 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)},
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user