mirror of
				https://github.com/mgechev/revive.git
				synced 2025-10-30 23:37:49 +02:00 
			
		
		
		
	Add tests for the arguments limit
This commit is contained in:
		
							
								
								
									
										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)}, | ||||
| 	}) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user