checker

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Strings     string = "string"
	Bytes       string = "[]byte"
	Byte        string = "byte"
	Rune        string = "rune"
	UntypedRune string = "untyped rune"
)

Variables

This section is empty.

Functions

func WrapPrint added in v0.2.0

func WrapPrint(fSet *token.FileSet) func(ast.Node) []byte

func WrapType added in v0.2.0

func WrapType(info *types.Info) func(node ast.Expr) string

Types

type Checker

type Checker struct {
	Violations []Violation           // List of available violations
	Packages   map[string][]int      // Storing indexes of Violations per pkg/kg.Struct
	Type       func(ast.Expr) string // Type Checker closure.
	Print      func(ast.Node) []byte // String representation of the expression.
}

Checker will perform standard check on package and its methods.

func New

func New(violations ...[]Violation) Checker

func (*Checker) Handle added in v0.2.0

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

func (*Checker) Match added in v0.2.0

func (c *Checker) Match(pkgName, name string) *Violation

Match will check the available violations we got from checks against the `name` caller from package `pkgName`.

func (*Checker) Matches added in v1.1.0

func (c *Checker) Matches(pkgName, name string) []*Violation

Matches do same thing as Match but return a slice of violations as only things that require this are bytes.Buffer and strings.Builder it only be used in matching methods in analyzer.

type Generate

type Generate struct {
	SkipGenerate bool
	PreCondition string   // Precondition we want to be generated
	Pattern      string   // Generate pattern (for the `want` message)
	Returns      []string // ReturnTypes as slice
}

Tests (generation) related struct.

type GolangIssue added in v0.2.0

type GolangIssue struct {
	Start     token.Position
	End       token.Position
	Message   string
	InlineFix string
	Original  string
}

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, pkg string) (string, bool)

type Violation

type Violation struct {
	Type     ViolationType //
	Args     []int         // Indexes of the arguments needs to be checked
	ArgsType string

	Targets    string
	Package    string
	AltPackage string
	Struct     string
	Caller     string
	AltCaller  string

	// --- tests generation information
	Generate *Generate
	// contains filtered or unexported fields
}

Violation describes what message we going to give to a particular code violation

func (*Violation) Diagnostic

func (v *Violation) Diagnostic(fSet *token.FileSet) analysis.Diagnostic

func (*Violation) Issue added in v0.2.0

func (v *Violation) Issue(fSet *token.FileSet) GolangIssue

Issue intended to be used only within `golangci-lint`, but you can use it alongside Diagnostic if you wish.

func (*Violation) Message

func (v *Violation) Message() string

func (*Violation) With added in v0.2.0

func (v *Violation) With(base []byte, e *ast.CallExpr, args map[int]ast.Expr) *Violation

type ViolationType

type ViolationType int

Type of violation: can be method or 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