lintutil

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: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsNode

func ContainsNode(root ast.Node, pred func(ast.Node) bool) bool

ContainsNode reports whether `FindNode(root, pred)!=nil`.

func CouldBeMutated

func CouldBeMutated(info *types.Info, body ast.Node, dst ast.Expr) bool

CouldBeMutated reports whether dst can be modified inside body.

Note that it does not take already existing pointers to dst. An example of safe and correct usage is checking of something that was just defined, so the dst is a result of that definition.

func FindNode

func FindNode(root ast.Node, followFunc, pred func(ast.Node) bool) ast.Node

FindNode applies pred for root and all it's childs until it returns true. If followFunc is defined, it's called before following any node to check whether it needs to be followed. followFunc has to return true in order to continuing traversing the node and return false otherwise. Matched node is returned. If none of the nodes matched predicate, nil is returned.

func IsImmutable

func IsImmutable(info *types.Info, n ast.Expr) bool

IsImmutable reports whether n can be modified through any operation.

func IsZeroValue added in v0.4.0

func IsZeroValue(info *types.Info, x ast.Expr) bool

IsZeroValue reports whether x represents zero value of its type.

The functions is conservative and may return false for zero values if some cases are not handled in a comprehensive way but is should never return true for something that's not a proper zv.

func ZeroValueOf added in v0.4.0

func ZeroValueOf(typeExpr ast.Expr, typ types.Type) ast.Expr

ZeroValueOf returns a zero value expression for typeExpr of type typ. If function can't find such a value, nil is returned.

Types

type AstSet

type AstSet struct {
	// contains filtered or unexported fields
}

AstSet is a simple ast.Node set. Zero value is ready to use set. Can be reused after Clear call.

func (*AstSet) Clear

func (s *AstSet) Clear()

Clear removes all element from set.

func (*AstSet) Contains

func (s *AstSet) Contains(x ast.Node) bool

Contains reports whether s contains x.

func (*AstSet) Insert

func (s *AstSet) Insert(x ast.Node) bool

Insert pushes x in s if it's not already there. Returns true if element was inserted.

func (*AstSet) Len

func (s *AstSet) Len() int

Len returns the number of elements contained inside s.

Jump to

Keyboard shortcuts

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