forked from forgejo/forgejo
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:
parent
4af7c47b38
commit
4f63f283c4
182 changed files with 15832 additions and 1226 deletions
67
vendor/github.com/mgechev/revive/rule/max-public-structs.go
generated
vendored
Normal file
67
vendor/github.com/mgechev/revive/rule/max-public-structs.go
generated
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
package rule
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/mgechev/revive/lint"
|
||||
)
|
||||
|
||||
// MaxPublicStructsRule lints given else constructs.
|
||||
type MaxPublicStructsRule struct{}
|
||||
|
||||
// Apply applies the rule to given file.
|
||||
func (r *MaxPublicStructsRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
|
||||
var failures []lint.Failure
|
||||
|
||||
fileAst := file.AST
|
||||
walker := &lintMaxPublicStructs{
|
||||
fileAst: fileAst,
|
||||
onFailure: func(failure lint.Failure) {
|
||||
failures = append(failures, failure)
|
||||
},
|
||||
}
|
||||
|
||||
ast.Walk(walker, fileAst)
|
||||
|
||||
max, ok := arguments[0].(int64) // Alt. non panicking version
|
||||
if !ok {
|
||||
panic(`invalid value passed as argument number to the "max-public-structs" rule`)
|
||||
}
|
||||
|
||||
if walker.current > max {
|
||||
walker.onFailure(lint.Failure{
|
||||
Failure: "you have exceeded the maximum number of public struct declarations",
|
||||
Confidence: 1,
|
||||
Node: fileAst,
|
||||
Category: "style",
|
||||
})
|
||||
}
|
||||
|
||||
return failures
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *MaxPublicStructsRule) Name() string {
|
||||
return "max-public-structs"
|
||||
}
|
||||
|
||||
type lintMaxPublicStructs struct {
|
||||
current int64
|
||||
fileAst *ast.File
|
||||
onFailure func(lint.Failure)
|
||||
}
|
||||
|
||||
func (w *lintMaxPublicStructs) Visit(n ast.Node) ast.Visitor {
|
||||
switch v := n.(type) {
|
||||
case *ast.TypeSpec:
|
||||
name := v.Name.Name
|
||||
first := string(name[0])
|
||||
if strings.ToUpper(first) == first {
|
||||
w.current++
|
||||
}
|
||||
break
|
||||
}
|
||||
return w
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue