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
66
vendor/github.com/mgechev/revive/rule/waitgroup-by-value.go
generated
vendored
Normal file
66
vendor/github.com/mgechev/revive/rule/waitgroup-by-value.go
generated
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
package rule
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
|
||||
"github.com/mgechev/revive/lint"
|
||||
)
|
||||
|
||||
// WaitGroupByValueRule lints sync.WaitGroup passed by copy in functions.
|
||||
type WaitGroupByValueRule struct{}
|
||||
|
||||
// Apply applies the rule to given file.
|
||||
func (r *WaitGroupByValueRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
|
||||
var failures []lint.Failure
|
||||
|
||||
onFailure := func(failure lint.Failure) {
|
||||
failures = append(failures, failure)
|
||||
}
|
||||
|
||||
w := lintWaitGroupByValueRule{onFailure: onFailure}
|
||||
ast.Walk(w, file.AST)
|
||||
return failures
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *WaitGroupByValueRule) Name() string {
|
||||
return "waitgroup-by-value"
|
||||
}
|
||||
|
||||
type lintWaitGroupByValueRule struct {
|
||||
onFailure func(lint.Failure)
|
||||
}
|
||||
|
||||
func (w lintWaitGroupByValueRule) Visit(node ast.Node) ast.Visitor {
|
||||
// look for function declarations
|
||||
fd, ok := node.(*ast.FuncDecl)
|
||||
if !ok {
|
||||
return w
|
||||
}
|
||||
|
||||
// Check all function's parameters
|
||||
for _, field := range fd.Type.Params.List {
|
||||
if !w.isWaitGroup(field.Type) {
|
||||
continue
|
||||
}
|
||||
|
||||
w.onFailure(lint.Failure{
|
||||
Confidence: 1,
|
||||
Node: field,
|
||||
Failure: "sync.WaitGroup passed by value, the function will get a copy of the original one",
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lintWaitGroupByValueRule) isWaitGroup(ft ast.Expr) bool {
|
||||
se, ok := ft.(*ast.SelectorExpr)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
x, _ := se.X.(*ast.Ident)
|
||||
sel := se.Sel.Name
|
||||
return x.Name == "sync" && sel == "WaitGroup"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue