Documentation ¶
Index ¶
- Variables
- func IsFunctionCall(node ast.Node) bool
- func IsFunctionLiteral(node ast.Node) bool
- func IsPointerType(t types.Type) bool
- func ReportConcrete(pass *analysis.Pass, capturedCall *CallViaReceiver, ...)
- func ReportInterface(pass *analysis.Pass, capturedCall *CallViaReceiver, ...)
- func ShouldCheckInterface(iface *ast.Ident, allowList, ignoreList []string) bool
- type CallViaReceiver
- type ConcreteParamType
- type InterfaceParamType
- type TypeChain
Constants ¶
This section is empty.
Variables ¶
var ( Loglvl = "info" // Captured usages of types implementing interfaces on the ignore list will // not be reported. InterfacesIgnoreList = arrayFlags{} // If not empty, only captured usages of types implementing interfaces on // the allow list will not be reported. InterfacesAllowList = arrayFlags{} )
Flags.
var Analyzer *analysis.Analyzer = &analysis.Analyzer{ Name: "ifacecapture", Doc: "Checks for possibly unintentional captures of variables implementing " + "an interface of a parameter in a callback function.", Run: run, Requires: []*analysis.Analyzer{ inspect.Analyzer, }, Flags: flag.FlagSet{}, RunDespiteErrors: false, ResultType: nil, FactTypes: nil, }
var ErrNoTypeInfo = fmt.Errorf("no type information available")
var ErrUnexpectedType = errors.New("unexpected type")
Functions ¶
func IsFunctionCall ¶
IsFunctionCall returns true if the given expression is of type `ast.CallExpr`.
func IsFunctionLiteral ¶
IsFunctionLiteral returns true if the given expression is of type `ast.FuncLit`.
func IsPointerType ¶
IsFunctionDeclaration returns true if the given type, when stringified, contains a '*'.
func ReportConcrete ¶
func ReportConcrete(pass *analysis.Pass, capturedCall *CallViaReceiver, paramType ConcreteParamType)
ReportConcrete reports that the receiver of `capturedCall` is the same concrete type as the type of `paramType`.
func ReportInterface ¶
func ReportInterface(pass *analysis.Pass, capturedCall *CallViaReceiver, iParamType InterfaceParamType)
ReportInterface reports that `call` implements the interface `iParamType`.
Types ¶
type CallViaReceiver ¶
type CallViaReceiver struct { // The type of the receiver for this call ReceivedByType types.Type // The chain of Selector expressions that lead to the function. E.g. in // a.b.c.foo(), the selectors are [a, b, c]. Chain []*ast.Ident // contains filtered or unexported fields }
CallViaReceiver represents a call to a function on a receiver, possibly through a chain of Selector expressions.
func NewCallViaReceiver ¶
func NewCallViaReceiver(tinfo *types.Info) CallViaReceiver
func (*CallViaReceiver) ProcessSelExpr ¶
func (c *CallViaReceiver) ProcessSelExpr(expr *ast.SelectorExpr) error
ProcessSelExpr recursively processes a SelectorExpr and adds the chain of Idents to the .Chain field.
func (CallViaReceiver) Receiver ¶
func (c CallViaReceiver) Receiver() *ast.Ident
Receiver returns the receiver for this call, which is the last element in the chain. Will panic if the chain is empty.
func (CallViaReceiver) String ¶
func (c CallViaReceiver) String() string
Formats the CallViaReceiver as a string in the form "a.b.c".
type ConcreteParamType ¶
type InterfaceParamType ¶
type TypeChain ¶
TypeChain traverses a chain of selector expressions like mypkg.MyInterface and collects the idents of the types in the chain.
func NewTypeChain ¶
func NewTypeChain() TypeChain
func (TypeChain) IsInterface ¶
IsInterface returns true if the last element of the chain is an interface.