code

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 21 Imported by: 22

Documentation

Overview

Package code answers structural and type questions about Go code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolConst

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

func BuildConstraints added in v0.5.0

func BuildConstraints(pass *analysis.Pass, f *ast.File) (constraint.Expr, bool)

BuildConstraints returns the build constraints for file f. It considers both //go:build lines as well as GOOS and GOARCH in file names.

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 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 IsOfPointerToTypeWithName added in v0.5.0

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

func IsOfStringConvertibleByteSlice added in v0.5.0

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

func IsOfTypeWithName added in v0.5.0

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

func LanguageVersion added in v0.5.0

func LanguageVersion(pass *analysis.Pass, node Positioner) string

LanguageVersion returns the version of the Go language that node has access to. This might differ from the version of the Go standard library.

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 RefersTo added in v0.5.0

func RefersTo(pass *analysis.Pass, expr ast.Expr, ident types.Object) bool

func SelectorName

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

func StdlibVersion added in v0.5.0

func StdlibVersion(pass *analysis.Pass, node Positioner) string

StdlibVersion returns the version of the Go standard library that node can expect to have access to. This might differ from the language version for versions of Go older than 1.21.

Types

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