Documentation
¶
Index ¶
- type Alternative
- type Checker
- func (c *Checker) Check(e *ast.CallExpr) *Violation
- func (c *Checker) HandleFunction(pkgName, methodName string) *Violation
- func (c *Checker) HandleMethod(receiver ast.Expr, method string) *Violation
- func (c *Checker) Type(node ast.Expr) string
- func (c *Checker) With(pass *analysis.Pass, i []Import, debugFn func(ast.Expr, string, ...any)) *Checker
- type Generate
- type Import
- type Imports
- type Violation
- type ViolationType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alternative ¶
type Checker ¶
type Checker struct { Package string Functions map[string]Violation Methods map[string]map[string]Violation // contains filtered or unexported fields }
Checker will perform standart check on package and its methods
func New ¶
New will accept a name for package (like `text/template` or `strings`) and returns a pointer to initial checker object.
func (*Checker) Check ¶
Check perform check on call expression in order to find out can the call expression to be substituted with an alternative method/function.
func (*Checker) HandleFunction ¶
HandleFunction will return Violation for next processing if function/method allows to be violated, so we can check its arguments, after confirming that we indeed have method from imported package.
func (*Checker) HandleMethod ¶
type Generate ¶
type Generate struct { PreCondition string // Precondition we want to be generated Pattern string // Generate pattern (for the `want` message) Returns int // Expected to return n elements }
Tests (generation) related struct.
type Import ¶
Imports represents an imported package in a nice for lookup way...
examples: import . "bytes" -> checker.Import{Pkg:"bytes", Val:"."} import name "bytes" -> checker.Import{Pkg:"bytes", Val:"name"}
type Violation ¶
type Violation struct { Type ViolationType // What type is violation? Method or Function? Message string // Message on violation detection Args []int // Indexes of the arguments needs to be checked StringTargeted bool // String is expected? []byte otherwise. Alternative Alternative // Alternative methods/functions to use. Generate *Generate // Rules for genetation of tests. }
Violation describs what message we going to give to a particular code violation
func (*Violation) Diagnostic ¶
func (v *Violation) Diagnostic(start, end token.Pos) *analysis.Diagnostic
type ViolationType ¶
type ViolationType int
Type of violation: can be methodor function
const ( Function ViolationType = iota + 1 Method )