Denis Isaev 87aae77943 Update gocritic
Fix #324, relates #314

1. Update gocritic to the latest version
2. Use proper gocritic checkers repo, old repo was archived
3. Get enabled by default gocritic checks in sync with go-critic: don't
enable performance, experimental and opinionated checks by default
4. Support of `enabled-tags` options for gocritic
5. Enable almost all gocritic checks for the project
6. Make rich debugging for gocritic
7. Meticulously validate gocritic checks config
2019-01-09 09:51:48 +03:00

42 lines
755 B
Go

package astwalk
import (
"go/ast"
"strings"
)
type commentWalker struct {
visitor CommentVisitor
}
func (w *commentWalker) WalkFile(f *ast.File) {
if !w.visitor.EnterFile(f) {
return
}
for _, cg := range f.Comments {
visitCommentGroups(cg, w.visitor.VisitComment)
}
}
func visitCommentGroups(cg *ast.CommentGroup, visit func(*ast.CommentGroup)) {
var group []*ast.Comment
visitGroup := func(list []*ast.Comment) {
if len(list) == 0 {
return
}
cg := &ast.CommentGroup{List: list}
visit(cg)
}
for _, comment := range cg.List {
if strings.HasPrefix(comment.Text, "/*") {
visitGroup(group)
group = group[:0]
visitGroup([]*ast.Comment{comment})
} else {
group = append(group, comment)
}
}
visitGroup(group)
}