@@ -35,50 +35,33 @@ func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []
35
35
r .configureOnce .Do (func () { r .configure (arguments ) })
36
36
37
37
var failures []lint.Failure
38
- onFailure := func (failure lint.Failure ) {
39
- failures = append (failures , failure )
40
- }
41
-
42
- walker := lintArgsNum {
43
- max : r .max ,
44
- onFailure : onFailure ,
45
- }
46
-
47
- ast .Walk (walker , file .AST )
48
-
49
- return failures
50
- }
51
-
52
- // Name returns the rule name.
53
- func (* ArgumentsLimitRule ) Name () string {
54
- return "argument-limit"
55
- }
56
38
57
- type lintArgsNum struct {
58
- max int
59
- onFailure func (lint.Failure )
60
- }
39
+ for _ , decl := range file .AST .Decls {
40
+ funcDecl , ok := decl .(* ast.FuncDecl )
41
+ if ! ok {
42
+ continue
43
+ }
61
44
62
- func (w lintArgsNum ) Visit (n ast.Node ) ast.Visitor {
63
- node , ok := n .(* ast.FuncDecl )
64
- if ! ok {
65
- return w
66
- }
45
+ numParams := 0
46
+ for _ , l := range funcDecl .Type .Params .List {
47
+ numParams += len (l .Names )
48
+ }
67
49
68
- num := 0
69
- for _ , l := range node .Type .Params .List {
70
- for range l .Names {
71
- num ++
50
+ if numParams <= r .max {
51
+ continue
72
52
}
73
- }
74
53
75
- if num > w .max {
76
- w .onFailure (lint.Failure {
54
+ failures = append (failures , lint.Failure {
77
55
Confidence : 1 ,
78
- Failure : fmt .Sprintf ("maximum number of arguments per function exceeded; max %d but got %d" , w .max , num ),
79
- Node : node .Type ,
56
+ Failure : fmt .Sprintf ("maximum number of arguments per function exceeded; max %d but got %d" , r .max , numParams ),
57
+ Node : funcDecl .Type ,
80
58
})
81
59
}
82
60
83
- return nil // skip visiting the body of the function
61
+ return failures
62
+ }
63
+
64
+ // Name returns the rule name.
65
+ func (* ArgumentsLimitRule ) Name () string {
66
+ return "argument-limit"
84
67
}
0 commit comments