v0.4.7 Latest Latest

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 18 Imported by: 19



Package code answers structural and type questions about Go code.



This section is empty.


This section is empty.


func BoolConst

func BoolConst(pass *analysis.Pass, expr ast.Expr) bool

func CallName

func CallName(pass *analysis.Pass, call *ast.CallExpr) string

func ExprToInt

func ExprToInt(pass *analysis.Pass, expr ast.Expr) (int64, bool)

func ExprToString

func ExprToString(pass *analysis.Pass, expr ast.Expr) (string, bool)

func File

func File(pass *analysis.Pass, node Positioner) *ast.File

func Generator

func Generator(pass *analysis.Pass, pos token.Pos) (generated.Generator, bool)

Generator returns the generator that generated the file containing pos. It ignores //line directives.

func IntegerLiteral added in v0.3.0

func IntegerLiteral(pass *analysis.Pass, node ast.Node) (types.TypeAndValue, bool)

func IsBoolConst

func IsBoolConst(pass *analysis.Pass, expr ast.Expr) bool

func IsCallTo

func IsCallTo(pass *analysis.Pass, node ast.Node, name string) bool

func IsCallToAny

func IsCallToAny(pass *analysis.Pass, node ast.Node, names ...string) bool

func IsGenerated

func IsGenerated(pass *analysis.Pass, pos token.Pos) bool

IsGenerated reports whether pos is in a generated file, It ignores //line directives.

func IsGoVersion

func IsGoVersion(pass *analysis.Pass, minor int) bool

func IsInTest

func IsInTest(pass *analysis.Pass, node Positioner) bool

func IsIntegerLiteral added in v0.3.0

func IsIntegerLiteral(pass *analysis.Pass, node ast.Node, value constant.Value) bool

func IsMain

func IsMain(pass *analysis.Pass) bool

IsMain reports whether the package being processed is a package main.

func IsMainLike

func IsMainLike(pass *analysis.Pass) bool

IsMainLike reports whether the package being processed is a main-like package. A main-like package is a package that is package main, or that is intended to be used by a tool framework such as cobra to implement a command.

Note that this function errs on the side of false positives; it may return true for packages that aren't main-like. IsMainLike is intended for analyses that wish to suppress diagnostics for main-like packages to avoid false positives.

func IsMethod added in v0.3.2

func IsMethod(pass *analysis.Pass, expr *ast.SelectorExpr, name string, meth *types.Signature) bool

IsMethod reports whether expr is a method call of a named method with signature meth. If name is empty, it is not checked. For now, method expressions (Type.Method(recv, ..)) are not considered method calls.

func IsNil

func IsNil(pass *analysis.Pass, expr ast.Expr) bool

func IsOfType

func IsOfType(pass *analysis.Pass, expr ast.Expr, name string) bool

func Match

func Match(pass *analysis.Pass, q pattern.Pattern, node ast.Node) (*pattern.Matcher, bool)

func MatchAndEdit

func MatchAndEdit(pass *analysis.Pass, before, after pattern.Pattern, node ast.Node) (*pattern.Matcher, []analysis.TextEdit, bool)

func MayHaveSideEffects

func MayHaveSideEffects(pass *analysis.Pass, expr ast.Expr, purity purity.Result) bool

MayHaveSideEffects reports whether expr may have side effects. If the purity argument is nil, this function implements a purely syntactic check, meaning that any function call may have side effects, regardless of the called function's body. Otherwise, purity will be consulted to determine the purity of function calls.

func Preorder

func Preorder(pass *analysis.Pass, fn func(ast.Node), types ...ast.Node)

func PreorderStack

func PreorderStack(pass *analysis.Pass, fn func(ast.Node, []ast.Node), types ...ast.Node)

func SelectorName

func SelectorName(pass *analysis.Pass, expr *ast.SelectorExpr) string


type Positioner

type Positioner interface {
	Pos() token.Pos

Jump to

Keyboard shortcuts

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