
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
81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
package astwalk
|
|
|
|
import (
|
|
"go/ast"
|
|
)
|
|
|
|
// Visitor interfaces.
|
|
type (
|
|
// DocCommentVisitor visits every doc-comment.
|
|
// Does not visit doc-comments for function-local definitions (types, etc).
|
|
// Also does not visit package doc-comment (file-level doc-comments).
|
|
DocCommentVisitor interface {
|
|
VisitDocComment(*ast.CommentGroup)
|
|
}
|
|
|
|
// FuncDeclVisitor visits every top-level function declaration.
|
|
FuncDeclVisitor interface {
|
|
walkerEvents
|
|
VisitFuncDecl(*ast.FuncDecl)
|
|
}
|
|
|
|
// ExprVisitor visits every expression inside AST file.
|
|
ExprVisitor interface {
|
|
walkerEvents
|
|
VisitExpr(ast.Expr)
|
|
}
|
|
|
|
// LocalExprVisitor visits every expression inside function body.
|
|
LocalExprVisitor interface {
|
|
walkerEvents
|
|
VisitLocalExpr(ast.Expr)
|
|
}
|
|
|
|
// StmtListVisitor visits every statement list inside function body.
|
|
// This includes block statement bodies as well as implicit blocks
|
|
// introduced by case clauses and alike.
|
|
StmtListVisitor interface {
|
|
walkerEvents
|
|
VisitStmtList([]ast.Stmt)
|
|
}
|
|
|
|
// StmtVisitor visits every statement inside function body.
|
|
StmtVisitor interface {
|
|
walkerEvents
|
|
VisitStmt(ast.Stmt)
|
|
}
|
|
|
|
// TypeExprVisitor visits every type describing expression.
|
|
// It also traverses struct types and interface types to run
|
|
// checker over their fields/method signatures.
|
|
TypeExprVisitor interface {
|
|
walkerEvents
|
|
VisitTypeExpr(ast.Expr)
|
|
}
|
|
|
|
// LocalCommentVisitor visits every comment inside function body.
|
|
LocalCommentVisitor interface {
|
|
walkerEvents
|
|
VisitLocalComment(*ast.CommentGroup)
|
|
}
|
|
|
|
// CommentVisitor visits every comment.
|
|
CommentVisitor interface {
|
|
walkerEvents
|
|
VisitComment(*ast.CommentGroup)
|
|
}
|
|
)
|
|
|
|
// walkerEvents describes common hooks available for most visitor types.
|
|
type walkerEvents interface {
|
|
// EnterFile is called for every file that is about to be traversed.
|
|
// If false is returned, file is not visited.
|
|
EnterFile(*ast.File) bool
|
|
|
|
// EnterFunc is called for every function declaration that is about
|
|
// to be traversed. If false is returned, function is not visited.
|
|
EnterFunc(*ast.FuncDecl) bool
|
|
|
|
skipChilds() bool
|
|
}
|