gettercheck

package
v0.0.0-...-38443d0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package gettercheck is the library used to implement the gettercheck command-line tool.

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:       "gettercheck",
	Doc:        "check for unused getters",
	Run:        runAnalyzer,
	ResultType: reflect.TypeOf(Result{}),
}
View Source
var (
	// ErrNoGoFiles is returned when CheckPackage is run on a package with no Go source files
	ErrNoGoFiles = errors.New("package contains no go source files")
)

Functions

func FindMethod

func FindMethod(p types.Type, methodName string) *types.Func

Types

type Checker

type Checker struct {
	// Exclusions defines code packages, symbols, and other elements that will not be checked.
	Exclusions Exclusions

	WriteGetters bool

	// The mod flag for go build.
	Mod string
}

Checker checks that you checked errors.

func (*Checker) CheckPackage

func (c *Checker) CheckPackage(pkg *packages.Package) Result

CheckPackage checks packages for errors that have not been checked.

It will exclude specific errors from analysis if the user has configured exclusions.

func (*Checker) LoadPackages

func (c *Checker) LoadPackages(paths ...string) ([]*packages.Package, error)

LoadPackages loads all the packages in all the paths provided. It uses the exclusions and build tags provided to by the user when loading the packages.

type Exclusions

type Exclusions struct {

	// TestFiles excludes _test.go files.
	TestFiles bool

	// GeneratedFiles excludes generated source files.
	//
	// Source file is assumed to be generated if its contents
	// match the following regular expression:
	//
	//   ^// Code generated .* DO NOT EDIT\\.$
	//
	GeneratedFiles bool
}

Exclusions define symbols and language elements that will be not checked

type Result

type Result struct {
	// UnusedGetterError is a list of all the unchecked errors in the package.
	// Printing an error reports its position within the file and the contents of the line.
	UnusedGetterError []UnusedGetterError
}

Result is returned from the CheckPackage function, and holds all the errors that were found to be unchecked in a package.

Aggregation can be done using the Append method for users that want to combine results from multiple packages.

func (*Result) Append

func (r *Result) Append(other Result)

Append appends errors to e. Append does not do any duplicate checking.

func (Result) Unique

func (r Result) Unique() Result

Returns the unique errors that have been accumulated. Duplicates may occur when a file containing an unchecked error belongs to > 1 package.

The method receiver remains unmodified after the call to Unique.

type UnaryVisitor

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

func (*UnaryVisitor) Visit

func (v *UnaryVisitor) Visit(c *astutil.Cursor) bool

type UnusedGetterError

type UnusedGetterError struct {
	//todo(sai): GetterPos
	Pos       token.Position
	GetterPos token.Position
	Line      string
	FuncName  string
}

UnusedGetterError indicates the position of an unused protobuf getter.

Directories

Path Synopsis
tests

Jump to

Keyboard shortcuts

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