checker

package
v0.0.0-...-a7a0a81 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2018 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(slug string, constructor NodeCheckerConstructor) error

Register adds `checker` to the registry.

Types

type BadRangeReferenceChecker

type BadRangeReferenceChecker struct{}

BadRangeReferenceChecker checks that vars declared in a range statement are not used by reference inside the body of the loop.

func (*BadRangeReferenceChecker) Check

func (c *BadRangeReferenceChecker) Check(
	node ast.Node, content string, report *Report)

Check implements the NodeChecker interface.

func (*BadRangeReferenceChecker) Description

func (c *BadRangeReferenceChecker) Description() string

Description implements the NodeChecker interface.

func (*BadRangeReferenceChecker) Examples

func (c *BadRangeReferenceChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*BadRangeReferenceChecker) Register

func (c *BadRangeReferenceChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*BadRangeReferenceChecker) Title

func (c *BadRangeReferenceChecker) Title() string

Title implements the NodeChecker interface.

type ConsistentReceiverNamesChecker

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

ConsistentReceiverNamesChecker checks that method receivers of a type are named consistently.

func (*ConsistentReceiverNamesChecker) Check

func (c *ConsistentReceiverNamesChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*ConsistentReceiverNamesChecker) Description

func (c *ConsistentReceiverNamesChecker) Description() string

Description implements the NodeChecker interface.

func (*ConsistentReceiverNamesChecker) Examples

func (c *ConsistentReceiverNamesChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*ConsistentReceiverNamesChecker) Register

Register implements the NodeChecker interface.

func (*ConsistentReceiverNamesChecker) Title

Title implements the NodeChecker interface.

type Error

type Error struct {

	// Pos is the position in a file where the error occurred.
	Pos token.Pos

	// Message is the error message.
	Message string
}

Error is a description of a checker violation.

type Example

type Example struct {

	// Good is an example of sticking to the rule.
	Good string

	// Bad is a counter-example showing a mis-use which lingo will report.
	Bad string
}

Example shows how to adhere and not adere to a rule.

type ExportedIdentDocChecker

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

ExportedIdentDocChecker checks the documentation of exported identifiers.

func (*ExportedIdentDocChecker) Check

func (c *ExportedIdentDocChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*ExportedIdentDocChecker) Description

func (c *ExportedIdentDocChecker) Description() string

Description implements the NodeChecker interface.

func (*ExportedIdentDocChecker) Examples

func (c *ExportedIdentDocChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*ExportedIdentDocChecker) Register

func (c *ExportedIdentDocChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*ExportedIdentDocChecker) Title

func (c *ExportedIdentDocChecker) Title() string

Title implements the NodeChecker interface.

type ExportedIdentDocCheckerConfig

type ExportedIdentDocCheckerConfig struct {

	// HasIdentPrefix signals if the checker should ensure that every doc comment begins
	// with the name of the item it describes.
	HasIdentPrefix bool `mapdecode:"has_ident_prefix"`
}

ExportedIdentDocCheckerConfig describes the configuration of a ExportedIdentDocChecker.

type FileChecker

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

FileChecker checks ast.File values for violations.

func NewFileChecker

func NewFileChecker() *FileChecker

NewFileChecker creates a new FileChecker.

func (*FileChecker) Check

func (c *FileChecker) Check(file *ast.File, content string, report *Report)

Check checks `file` for violations and registers them in `report`.

func (*FileChecker) On

func (c *FileChecker) On(nodeType interface{}, checker NodeChecker)

On registers `checker` for specific node type inferred from the type of `nodeType`.

func (*FileChecker) Register

func (c *FileChecker) Register(checkers ...NodeChecker)

Register registers all `checkers`.

type FuncCycloChecker

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

FuncCycloChecker checks that funcs are within specific cyclomatic complexity.

func (*FuncCycloChecker) Check

func (c *FuncCycloChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*FuncCycloChecker) Description

func (c *FuncCycloChecker) Description() string

Description implements the NodeChecker interface.

func (*FuncCycloChecker) Examples

func (c *FuncCycloChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*FuncCycloChecker) Register

func (c *FuncCycloChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*FuncCycloChecker) Title

func (c *FuncCycloChecker) Title() string

Title implements the NodeChecker interface.

type FuncCycloConfig

type FuncCycloConfig struct {

	// Max is the maximum cyclomatic complexity of a func.
	Max int `mapdecode:"max"`
}

FuncCycloConfig describes the configuration of a FuncCycloChecker.

type FuncParamsCountChecker

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

FuncParamsCountChecker checks that funcs have a limited number of parameters.

func (*FuncParamsCountChecker) Check

func (c *FuncParamsCountChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*FuncParamsCountChecker) Description

func (c *FuncParamsCountChecker) Description() string

Description implements the NodeChecker interface.

func (*FuncParamsCountChecker) Examples

func (c *FuncParamsCountChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*FuncParamsCountChecker) Register

func (c *FuncParamsCountChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*FuncParamsCountChecker) Title

func (c *FuncParamsCountChecker) Title() string

Title implements the NodeChecker interface.

type FuncParamsCountConfig

type FuncParamsCountConfig struct {

	// Max is the maximum number of parameters of a func.
	Max int `mapdecode:"max"`
}

FuncParamsCountConfig describes the configuration of a FuncParamsCountChecker.

type FuncResultsCountChecker

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

FuncResultsCountChecker checks that funcs have a limited number of results.

func (*FuncResultsCountChecker) Check

func (c *FuncResultsCountChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*FuncResultsCountChecker) Description

func (c *FuncResultsCountChecker) Description() string

Description implements the NodeChecker interface.

func (*FuncResultsCountChecker) Examples

func (c *FuncResultsCountChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*FuncResultsCountChecker) Register

func (c *FuncResultsCountChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*FuncResultsCountChecker) Title

func (c *FuncResultsCountChecker) Title() string

Title implements the NodeChecker interface.

type FuncResultsCountConfig

type FuncResultsCountConfig struct {

	// Max is the maximum number of results of a func.
	Max int `mapdecode:"max"`
}

FuncResultsCountConfig describes the configuration of a FuncResultsCountChecker.

type GroupParamTypesChecker

type GroupParamTypesChecker struct{}

GroupParamTypesChecker checks that func parameters are grouped by type.

func (*GroupParamTypesChecker) Check

func (c *GroupParamTypesChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*GroupParamTypesChecker) Description

func (c *GroupParamTypesChecker) Description() string

Description implements the NodeChecker interface.

func (*GroupParamTypesChecker) Examples

func (c *GroupParamTypesChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*GroupParamTypesChecker) Register

func (c *GroupParamTypesChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*GroupParamTypesChecker) Title

func (c *GroupParamTypesChecker) Title() string

Title implements the NodeChecker interface.

type LeftQuantifiersChecker

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

LeftQuantifiersChecker checks that when a basic literal appears in a binary expression it is the left operand.

func (*LeftQuantifiersChecker) Check

func (c *LeftQuantifiersChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*LeftQuantifiersChecker) Description

func (c *LeftQuantifiersChecker) Description() string

Description implements the NodeChecker interface.

func (*LeftQuantifiersChecker) Examples

func (c *LeftQuantifiersChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*LeftQuantifiersChecker) Register

func (c *LeftQuantifiersChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*LeftQuantifiersChecker) Title

func (c *LeftQuantifiersChecker) Title() string

Title implements the NodeChecker interface.

type LineLengthChecker

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

LineLengthChecker checks that code lines are within specific length limits.

func (*LineLengthChecker) Check

func (c *LineLengthChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*LineLengthChecker) Description

func (c *LineLengthChecker) Description() string

Description implements the NodeChecker interface.

func (*LineLengthChecker) Examples

func (c *LineLengthChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*LineLengthChecker) Register

func (c *LineLengthChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*LineLengthChecker) Title

func (c *LineLengthChecker) Title() string

Title implements the NodeChecker interface.

type LineLengthConfig

type LineLengthConfig struct {

	// MaxLength is the maximum number of characters permitted on a single line.
	MaxLength int `mapdecode:"max_length"`

	// TabWidth is the number of characters equivalent to a single tab.
	TabWidth int `mapdecode:"tab_width"`
}

LineLengthConfig describes the configuration of a LineLengthChecker.

type LocalReturnChecker

type LocalReturnChecker struct{}

LocalReturnChecker checks that exported funcs return exported (and internal) types only.

func (*LocalReturnChecker) Check

func (c *LocalReturnChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*LocalReturnChecker) Description

func (c *LocalReturnChecker) Description() string

Description implements the NodeChecker interface.

func (*LocalReturnChecker) Examples

func (c *LocalReturnChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*LocalReturnChecker) Register

func (c *LocalReturnChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*LocalReturnChecker) Title

func (c *LocalReturnChecker) Title() string

Title implements the NodeChecker interface.

type MultiWordIdentNameChecker

type MultiWordIdentNameChecker struct{}

MultiWordIdentNameChecker checks the correctness of type names. Correct type names adhere to the following rules: * PascalCase for exported types. * camelCase for non-exported types.

func (*MultiWordIdentNameChecker) Check

func (c *MultiWordIdentNameChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*MultiWordIdentNameChecker) Description

func (c *MultiWordIdentNameChecker) Description() string

Description implements the NodeChecker interface.

func (*MultiWordIdentNameChecker) Examples

func (c *MultiWordIdentNameChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*MultiWordIdentNameChecker) Register

func (c *MultiWordIdentNameChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*MultiWordIdentNameChecker) Title

func (c *MultiWordIdentNameChecker) Title() string

Title implements the NodeChecker interface.

type NodeChecker

type NodeChecker interface {

	// Title returns the title of the node checker.
	Title() string

	// Description returns the detailed description of the node checker.
	Description() string

	// Examples is a set of examples that demonstrate the node checker rule.
	Examples() []Example

	// Register registers the node checker for specific types
	// of nodes in `fc`.
	Register(fc *FileChecker)

	// Check checks `node` and registers violations in `report`.
	Check(node ast.Node, content string, report *Report)
}

NodeChecker checks ast.Node values for violations.

func Get

func Get(slug string, config interface{}) NodeChecker

Get returns the NodeChecker referenced by a `slug`.

func NewBadRangeReferenceChecker

func NewBadRangeReferenceChecker(configData interface{}) NodeChecker

NewBadRangeReferenceChecker constructs a new BadRangeReferenceChecker.

func NewConsistentReceiverNamesChecker

func NewConsistentReceiverNamesChecker(configData interface{}) NodeChecker

NewConsistentReceiverNamesChecker constructs a ConsistentReceiverNamesChecker.

func NewExportedIdentDocChecker

func NewExportedIdentDocChecker(configData interface{}) NodeChecker

NewExportedIdentDocChecker constructs a ExportedIdentDocChecker.

func NewFuncCycloChecker

func NewFuncCycloChecker(configData interface{}) NodeChecker

NewFuncCycloChecker constructs a FuncCycloChecker.

func NewFuncParamsCountChecker

func NewFuncParamsCountChecker(configData interface{}) NodeChecker

NewFuncParamsCountChecker constructs a FuncParamsCountChecker.

func NewFuncResultsCountChecker

func NewFuncResultsCountChecker(configData interface{}) NodeChecker

NewFuncResultsCountChecker constructs a FuncResultsCountChecker.

func NewGroupParamTypesChecker

func NewGroupParamTypesChecker(configData interface{}) NodeChecker

NewGroupParamTypesChecker constructs a GroupParamTypesChecker.

func NewLeftQuantifiersChecker

func NewLeftQuantifiersChecker(configData interface{}) NodeChecker

NewLeftQuantifiersChecker constructs a LeftQuantifiersChecker.

func NewLineLengthChecker

func NewLineLengthChecker(configData interface{}) NodeChecker

NewLineLengthChecker constructs a LineLengthChecker.

func NewLocalReturnChecker

func NewLocalReturnChecker(configData interface{}) NodeChecker

NewLocalReturnChecker constructs a LocalReturnChecker.

func NewMultiWordIdentNameChecker

func NewMultiWordIdentNameChecker(configData interface{}) NodeChecker

NewMultiWordIdentNameChecker constructs a MultiWordIdentNameChecker.

func NewPassContextFirstChecker

func NewPassContextFirstChecker(configData interface{}) NodeChecker

NewPassContextFirstChecker constructs a PassContextFirstChecker.

func NewRedundantElseChecker

func NewRedundantElseChecker(configData interface{}) NodeChecker

NewRedundantElseChecker constructs a RedundantElseChecker.

func NewReturnErrorLastChecker

func NewReturnErrorLastChecker(configData interface{}) NodeChecker

NewReturnErrorLastChecker constructs a ReturnErrorLastChecker.

func NewTestPackageChecker

func NewTestPackageChecker(configData interface{}) NodeChecker

NewTestPackageChecker constructs a TestPackageChecker.

func NewUnneededImportAliasChecker

func NewUnneededImportAliasChecker(configData interface{}) NodeChecker

NewUnneededImportAliasChecker constructs a UnneededImportAliasChecker.

type NodeCheckerConstructor

type NodeCheckerConstructor func(configData interface{}) NodeChecker

NodeCheckerConstructor constructs NodeChecker instances.

type PassContextFirstChecker

type PassContextFirstChecker struct{}

PassContextFirstChecker checks that if a function declaration contains a context, it is the first argument.

func (*PassContextFirstChecker) Check

func (c *PassContextFirstChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*PassContextFirstChecker) Description

func (c *PassContextFirstChecker) Description() string

Description implements the NodeChecker interface.

func (*PassContextFirstChecker) Examples

func (c *PassContextFirstChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*PassContextFirstChecker) Register

func (c *PassContextFirstChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*PassContextFirstChecker) Title

func (c *PassContextFirstChecker) Title() string

Title implements the NodeChecker interface.

type RedundantElseChecker

type RedundantElseChecker struct{}

RedundantElseChecker checks that if the body of an 'if' statement ends with a terminating statement, there is no 'else' statement.

func (*RedundantElseChecker) Check

func (c *RedundantElseChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*RedundantElseChecker) Description

func (c *RedundantElseChecker) Description() string

Description implements the NodeChecker interface.

func (*RedundantElseChecker) Examples

func (c *RedundantElseChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*RedundantElseChecker) Register

func (c *RedundantElseChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*RedundantElseChecker) Title

func (c *RedundantElseChecker) Title() string

Title implements the NodeChecker interface.

type Report

type Report struct {

	// Errors contains all violations registered by the checkers.
	Errors []Error
}

Report collects the results of a run of some checkers.

type ReturnErrorLastChecker

type ReturnErrorLastChecker struct{}

ReturnErrorLastChecker checks that error is the last value returned by a func.

func (*ReturnErrorLastChecker) Check

func (c *ReturnErrorLastChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*ReturnErrorLastChecker) Description

func (c *ReturnErrorLastChecker) Description() string

Description implements the NodeChecker interface.

func (*ReturnErrorLastChecker) Examples

func (c *ReturnErrorLastChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*ReturnErrorLastChecker) Register

func (c *ReturnErrorLastChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*ReturnErrorLastChecker) Title

func (c *ReturnErrorLastChecker) Title() string

Title implements the NodeChecker interface.

type TestPackageChecker

type TestPackageChecker struct{}

TestPackageChecker checks that tests are placed in "*_test" packages only.

func (*TestPackageChecker) Check

func (c *TestPackageChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*TestPackageChecker) Description

func (c *TestPackageChecker) Description() string

Description implements the NodeChecker interface.

func (*TestPackageChecker) Examples

func (c *TestPackageChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*TestPackageChecker) Register

func (c *TestPackageChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*TestPackageChecker) Title

func (c *TestPackageChecker) Title() string

Title implements the NodeChecker interface.

type UnneededImportAliasChecker

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

UnneededImportAliasChecker checks that import aliases are used only when necessary.

func (*UnneededImportAliasChecker) Check

func (c *UnneededImportAliasChecker) Check(
	node ast.Node,
	content string,
	report *Report)

Check implements the NodeChecker interface.

func (*UnneededImportAliasChecker) Description

func (c *UnneededImportAliasChecker) Description() string

Description implements the NodeChecker interface.

func (*UnneededImportAliasChecker) Examples

func (c *UnneededImportAliasChecker) Examples() []Example

Examples implements the NodeChecker interface.

func (*UnneededImportAliasChecker) Register

func (c *UnneededImportAliasChecker) Register(fc *FileChecker)

Register implements the NodeChecker interface.

func (*UnneededImportAliasChecker) Title

Title implements the NodeChecker interface.

Jump to

Keyboard shortcuts

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