update revive lint to latest commit (#12921)

* update revive lint to latest commit

* make fmt

* change import
This commit is contained in:
techknowlogick 2020-09-22 13:02:16 -04:00 committed by GitHub
parent 63e8bdaf73
commit 1c3278c2fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
154 changed files with 5965 additions and 8502 deletions

View file

@ -3,6 +3,7 @@ package analysis
import (
"fmt"
"reflect"
"strings"
"unicode"
)
@ -58,14 +59,28 @@ func Validate(analyzers []*Analyzer) error {
}
// recursion
for i, req := range a.Requires {
for _, req := range a.Requires {
if err := visit(req); err != nil {
return fmt.Errorf("%s.Requires[%d]: %v", a.Name, i, err)
return err
}
}
color[a] = black
}
if color[a] == grey {
stack := []*Analyzer{a}
inCycle := map[string]bool{}
for len(stack) > 0 {
current := stack[len(stack)-1]
stack = stack[:len(stack)-1]
if color[current] == grey && !inCycle[current.Name] {
inCycle[current.Name] = true
stack = append(stack, current.Requires...)
}
}
return &CycleInRequiresGraphError{AnalyzerNames: inCycle}
}
return nil
}
for _, a := range analyzers {
@ -95,3 +110,17 @@ func validIdent(name string) bool {
}
return name != ""
}
type CycleInRequiresGraphError struct {
AnalyzerNames map[string]bool
}
func (e *CycleInRequiresGraphError) Error() string {
var b strings.Builder
b.WriteString("cycle detected involving the following analyzers:")
for n := range e.AnalyzerNames {
b.WriteByte(' ')
b.WriteString(n)
}
return b.String()
}