Documentation
¶
Overview ¶
Package astutil provides shared AST/type helper functions used by linters.
Index ¶
- func CalledOSFunc(pass *analysis.Pass, call *ast.CallExpr, allowedNames ...string) (*types.Func, bool)
- func ContextContextType(pass *analysis.Pass) types.Type
- func ContextParamName(pass *analysis.Pass, fn *ast.FuncType) (string, bool)
- func EnclosingFuncType(node ast.Node) *ast.FuncType
- func FlipComparisonOp(op token.Token) token.Token
- func Inspector(pass *analysis.Pass) (*inspector.Inspector, error)
- func IsFmtErrorf(pass *analysis.Pass, call *ast.CallExpr) bool
- func IsGoOrDeferClosure(funcLitCur inspector.Cursor) bool
- func IsLocalObject(obj types.Object) bool
- func IsPkgSelector(pass *analysis.Pass, sel *ast.SelectorExpr, pkgPath string) bool
- func IsStringLiteral(expr ast.Expr) bool
- func NodeText(fset *token.FileSet, node ast.Node) string
- func RhsExprForIndex(rhs []ast.Expr, idx int) (ast.Expr, bool)
- func Root(pass *analysis.Pass) (inspector.Cursor, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalledOSFunc ¶ added in v0.82.3
func CalledOSFunc(pass *analysis.Pass, call *ast.CallExpr, allowedNames ...string) (*types.Func, bool)
CalledOSFunc reports whether call resolves to a function in package os. If allowedNames are provided, the function name must match one of them.
func ContextContextType ¶ added in v0.82.3
ContextContextType returns the types.Type for context.Context, or nil if the context package is not imported.
func ContextParamName ¶ added in v0.82.3
ContextParamName returns the name of the first context.Context parameter in fn, and true, or "", false if none exists.
func EnclosingFuncType ¶ added in v0.82.3
EnclosingFuncType extracts a function type from a FuncDecl or FuncLit node.
func FlipComparisonOp ¶ added in v0.82.3
FlipComparisonOp returns the comparison operator with left and right operands swapped.
func Inspector ¶ added in v0.79.4
Inspector extracts the *inspector.Inspector from pass.ResultOf. It returns an error if the result has an unexpected type.
func IsFmtErrorf ¶
IsFmtErrorf reports whether call is a call to fmt.Errorf (including aliases).
func IsGoOrDeferClosure ¶ added in v0.82.3
IsGoOrDeferClosure reports whether the FuncLit at funcLitCur is the direct callee of a go or defer statement, handling parenthesized forms like defer (func(){})().
func IsLocalObject ¶
IsLocalObject reports whether obj is a local (non-package-scope) object.
func IsPkgSelector ¶ added in v0.80.5
IsPkgSelector reports whether sel is a selector on an imported package with the given import path.
func IsStringLiteral ¶
IsStringLiteral reports whether expr is a string literal.
func RhsExprForIndex ¶
RhsExprForIndex returns the RHS expression mapped to idx when available. When rhs has a single expression, only idx==0 is considered mapped.
Types ¶
This section is empty.