astwalk

package
v0.11.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WalkerForComment

func WalkerForComment(v CommentVisitor) linter.FileWalker

WalkerForComment returns file walker implementation for CommentVisitor.

func WalkerForDocComment

func WalkerForDocComment(v DocCommentVisitor) linter.FileWalker

WalkerForDocComment returns file walker implementation for DocCommentVisitor.

func WalkerForExpr

func WalkerForExpr(v ExprVisitor) linter.FileWalker

WalkerForExpr returns file walker implementation for ExprVisitor.

func WalkerForFuncDecl

func WalkerForFuncDecl(v FuncDeclVisitor) linter.FileWalker

WalkerForFuncDecl returns file walker implementation for FuncDeclVisitor.

func WalkerForLocalComment

func WalkerForLocalComment(v LocalCommentVisitor) linter.FileWalker

WalkerForLocalComment returns file walker implementation for LocalCommentVisitor.

func WalkerForLocalDef

func WalkerForLocalDef(v LocalDefVisitor, info *types.Info) linter.FileWalker

WalkerForLocalDef returns file walker implementation for LocalDefVisitor.

func WalkerForLocalExpr

func WalkerForLocalExpr(v LocalExprVisitor) linter.FileWalker

WalkerForLocalExpr returns file walker implementation for LocalExprVisitor.

func WalkerForStmt

func WalkerForStmt(v StmtVisitor) linter.FileWalker

WalkerForStmt returns file walker implementation for StmtVisitor.

func WalkerForStmtList

func WalkerForStmtList(v StmtListVisitor) linter.FileWalker

WalkerForStmtList returns file walker implementation for StmtListVisitor.

func WalkerForTypeExpr

func WalkerForTypeExpr(v TypeExprVisitor, info *types.Info) linter.FileWalker

WalkerForTypeExpr returns file walker implementation for TypeExprVisitor.

Types

type CommentVisitor

type CommentVisitor interface {
	VisitComment(*ast.CommentGroup)
	// contains filtered or unexported methods
}

CommentVisitor visits every comment.

type DocCommentVisitor

type DocCommentVisitor interface {
	VisitDocComment(*ast.CommentGroup)
}

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).

type ExprVisitor

type ExprVisitor interface {
	VisitExpr(ast.Expr)
	// contains filtered or unexported methods
}

ExprVisitor visits every expression inside AST file.

type FuncDeclVisitor

type FuncDeclVisitor interface {
	VisitFuncDecl(*ast.FuncDecl)
	// contains filtered or unexported methods
}

FuncDeclVisitor visits every top-level function declaration.

type LocalCommentVisitor

type LocalCommentVisitor interface {
	VisitLocalComment(*ast.CommentGroup)
	// contains filtered or unexported methods
}

LocalCommentVisitor visits every comment inside function body.

type LocalDefVisitor

type LocalDefVisitor interface {
	VisitLocalDef(Name, ast.Expr)
	// contains filtered or unexported methods
}

LocalDefVisitor visits every name definitions inside a function.

Next elements are considered as name definitions:

  • Function parameters (input, output, receiver)
  • Every LHS of ":=" assignment that defines a new name
  • Every local var/const declaration.

NOTE: this visitor is experimental. This is also why it lives in a separate file.

type LocalExprVisitor

type LocalExprVisitor interface {
	VisitLocalExpr(ast.Expr)
	// contains filtered or unexported methods
}

LocalExprVisitor visits every expression inside function body.

type Name

type Name struct {
	ID   *ast.Ident
	Kind NameKind

	// Index is NameVar-specific field that is used to
	// specify nth tuple element being assigned to the name.
	Index int
}

Name holds ver/const/param definition symbol info.

type NameKind

type NameKind int

NameKind describes what kind of name Name object holds.

const (
	// NameParam is function/method receiver/input/output name.
	// Initializing expression is always nil.
	NameParam NameKind = iota
	// NameVar is var or ":=" declared name.
	// Initializing expression may be nil for var-declared names
	// without explicit initializing expression.
	NameVar
	// NameConst is const-declared name.
	// Initializing expression is never nil.
	NameConst
)

NOTE: set of name kinds is not stable and may change over time.

TODO(quasilyte): is NameRecv/NameParam/NameResult granularity desired? TODO(quasilyte): is NameVar/NameBind (var vs :=) granularity desired?

type StmtListVisitor

type StmtListVisitor interface {
	VisitStmtList(ast.Node, []ast.Stmt)
	// contains filtered or unexported methods
}

StmtListVisitor visits every statement list inside function body. This includes block statement bodies as well as implicit blocks introduced by case clauses and alike.

type StmtVisitor

type StmtVisitor interface {
	VisitStmt(ast.Stmt)
	// contains filtered or unexported methods
}

StmtVisitor visits every statement inside function body.

type TypeExprVisitor

type TypeExprVisitor interface {
	VisitTypeExpr(ast.Expr)
	// contains filtered or unexported methods
}

TypeExprVisitor visits every type describing expression. It also traverses struct types and interface types to run checker over their fields/method signatures.

type WalkHandler

type WalkHandler struct {
	// SkipChilds controls whether currently analyzed
	// node childs should be traversed.
	//
	// Value is reset after each visitor invocation,
	// so there is no need to set value back to false.
	SkipChilds bool
}

WalkHandler is a type to be embedded into every checker that uses astwalk walkers.

func (*WalkHandler) EnterFile

func (w *WalkHandler) EnterFile(f *ast.File) bool

EnterFile is a default walkerEvents.EnterFile implementation that reports every file as accepted candidate for checking.

func (*WalkHandler) EnterFunc

func (w *WalkHandler) EnterFunc(decl *ast.FuncDecl) bool

EnterFunc is a default walkerEvents.EnterFunc implementation that skips extern function (ones that do not have body).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL