mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Rename scripts to build and add revive command as a new build tool command (#10942)
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
		
							
								
								
									
										67
									
								
								vendor/github.com/mgechev/revive/rule/argument-limit.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								vendor/github.com/mgechev/revive/rule/argument-limit.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,67 @@
 | 
			
		||||
package rule
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"go/ast"
 | 
			
		||||
 | 
			
		||||
	"github.com/mgechev/revive/lint"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ArgumentsLimitRule lints given else constructs.
 | 
			
		||||
type ArgumentsLimitRule struct{}
 | 
			
		||||
 | 
			
		||||
// Apply applies the rule to given file.
 | 
			
		||||
func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
 | 
			
		||||
	if len(arguments) != 1 {
 | 
			
		||||
		panic(`invalid configuration for "argument-limit"`)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	total, ok := arguments[0].(int64) // Alt. non panicking version
 | 
			
		||||
	if !ok {
 | 
			
		||||
		panic(`invalid value passed as argument number to the "argument-list" rule`)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var failures []lint.Failure
 | 
			
		||||
 | 
			
		||||
	walker := lintArgsNum{
 | 
			
		||||
		total: int(total),
 | 
			
		||||
		onFailure: func(failure lint.Failure) {
 | 
			
		||||
			failures = append(failures, failure)
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ast.Walk(walker, file.AST)
 | 
			
		||||
 | 
			
		||||
	return failures
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Name returns the rule name.
 | 
			
		||||
func (r *ArgumentsLimitRule) Name() string {
 | 
			
		||||
	return "argument-limit"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type lintArgsNum struct {
 | 
			
		||||
	total     int
 | 
			
		||||
	onFailure func(lint.Failure)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (w lintArgsNum) Visit(n ast.Node) ast.Visitor {
 | 
			
		||||
	node, ok := n.(*ast.FuncDecl)
 | 
			
		||||
	if ok {
 | 
			
		||||
		num := 0
 | 
			
		||||
		for _, l := range node.Type.Params.List {
 | 
			
		||||
			for range l.Names {
 | 
			
		||||
				num++
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if num > w.total {
 | 
			
		||||
			w.onFailure(lint.Failure{
 | 
			
		||||
				Confidence: 1,
 | 
			
		||||
				Failure:    fmt.Sprintf("maximum number of arguments per function exceeded; max %d but got %d", w.total, num),
 | 
			
		||||
				Node:       node.Type,
 | 
			
		||||
			})
 | 
			
		||||
			return w
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return w
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user