checker

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alternative

type Alternative struct {
	Package  string
	Function string
	Method   string
}

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

func New(importedPackage string) *Checker

New will accept a name for package (like `text/template` or `strings`) and returns a pointer to initial checker object.

func (*Checker) Check

func (c *Checker) Check(e *ast.CallExpr) *Violation

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

func (c *Checker) HandleFunction(pkgName, methodName string) *Violation

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

func (c *Checker) HandleMethod(receiver ast.Expr, method string) *Violation

func (*Checker) Type

func (c *Checker) Type(node ast.Expr) string

func (*Checker) With

func (c *Checker) With(pass *analysis.Pass, i []Import, debugFn func(ast.Expr, string, ...any)) *Checker

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

type Import struct {
	Pkg  string // package name
	Name string // alias
}

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 Imports

type Imports map[string][]Import

func Load

func Load(fs *token.FileSet, ins *inspector.Inspector) Imports

func (Imports) Lookup

func (i Imports) Lookup(file string) []Import

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

func (*Violation) Handle

func (v *Violation) Handle(ce *ast.CallExpr) (m map[int]ast.Expr, ok bool)

func (*Violation) Targets

func (v *Violation) Targets() string

func (*Violation) WithAltArgs

func (v *Violation) WithAltArgs(m map[int]ast.Expr) *Violation

TODO: not implemented

type ViolationType

type ViolationType int

Type of violation: can be methodor function

const (
	Function ViolationType = iota + 1
	Method
)

Jump to

Keyboard shortcuts

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