package code
import "honnef.co/go/tools/analysis/code"
Package code answers structural and type questions about Go code.
Index ¶
- func BoolConst(pass *analysis.Pass, expr ast.Expr) bool
- func BuildConstraints(pass *analysis.Pass, f *ast.File) (constraint.Expr, bool)
- func CallName(pass *analysis.Pass, call *ast.CallExpr) string
- func ExprToInt(pass *analysis.Pass, expr ast.Expr) (int64, bool)
- func ExprToString(pass *analysis.Pass, expr ast.Expr) (string, bool)
- func File(pass *analysis.Pass, node Positioner) *ast.File
- func Generator(pass *analysis.Pass, pos token.Pos) (generated.Generator, bool)
- func IntegerLiteral(pass *analysis.Pass, node ast.Node) (types.TypeAndValue, bool)
- func IsBoolConst(pass *analysis.Pass, expr ast.Expr) bool
- func IsCallTo(pass *analysis.Pass, node ast.Node, name string) bool
- func IsCallToAny(pass *analysis.Pass, node ast.Node, names ...string) bool
- func IsGenerated(pass *analysis.Pass, pos token.Pos) bool
- func IsInTest(pass *analysis.Pass, node Positioner) bool
- func IsIntegerLiteral(pass *analysis.Pass, node ast.Node, value constant.Value) bool
- func IsMain(pass *analysis.Pass) bool
- func IsMainLike(pass *analysis.Pass) bool
- func IsMethod(pass *analysis.Pass, expr *ast.SelectorExpr, name string, meth *types.Signature) bool
- func IsNil(pass *analysis.Pass, expr ast.Expr) bool
- func IsOfPointerToTypeWithName(pass *analysis.Pass, expr ast.Expr, name string) bool
- func IsOfStringConvertibleByteSlice(pass *analysis.Pass, expr ast.Expr) bool
- func IsOfTypeWithName(pass *analysis.Pass, expr ast.Expr, name string) bool
- func LanguageVersion(pass *analysis.Pass, node Positioner) string
- func Match(pass *analysis.Pass, q pattern.Pattern, node ast.Node) (*pattern.Matcher, bool)
- func MatchAndEdit(pass *analysis.Pass, before, after pattern.Pattern, node ast.Node) (*pattern.Matcher, []analysis.TextEdit, bool)
- func MayHaveSideEffects(pass *analysis.Pass, expr ast.Expr, purity purity.Result) bool
- func Preorder(pass *analysis.Pass, fn func(ast.Node), types ...ast.Node)
- func PreorderStack(pass *analysis.Pass, fn func(ast.Node, []ast.Node), types ...ast.Node)
- func RefersTo(pass *analysis.Pass, expr ast.Expr, ident types.Object) bool
- func SelectorName(pass *analysis.Pass, expr *ast.SelectorExpr) string
- func StdlibVersion(pass *analysis.Pass, node Positioner) string
- type Positioner
Functions ¶
func BoolConst ¶
func BuildConstraints ¶
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 ExprToInt ¶
func ExprToString ¶
func File ¶
func File(pass *analysis.Pass, node Positioner) *ast.File
func Generator ¶
Generator returns the generator that generated the file containing pos. It ignores //line directives.
func IntegerLiteral ¶
func IsBoolConst ¶
func IsCallTo ¶
func IsCallToAny ¶
func IsGenerated ¶
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 ¶
func IsMain ¶
IsMain reports whether the package being processed is a package main.
func IsMainLike ¶
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 ¶
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 IsOfPointerToTypeWithName ¶
func IsOfStringConvertibleByteSlice ¶
func IsOfTypeWithName ¶
func LanguageVersion ¶
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 MatchAndEdit ¶
func MatchAndEdit(pass *analysis.Pass, before, after pattern.Pattern, node ast.Node) (*pattern.Matcher, []analysis.TextEdit, bool)
func MayHaveSideEffects ¶
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 PreorderStack ¶
func RefersTo ¶
func SelectorName ¶
func SelectorName(pass *analysis.Pass, expr *ast.SelectorExpr) string
func StdlibVersion ¶
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 ¶
Source Files ¶
code.go visit.go
- Version
- v0.6.1 (latest)
- Published
- Mar 5, 2025
- Platform
- windows/amd64
- Imports
- 21 packages
- Last checked
- 14 seconds ago –
Tools for package owners.