pepperlint

package module
v0.0.0-...-8bd899d Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

README

Pepperlint

Description

Pepperlint is a linter that allows for easy extensibility by allow for implementers to add their own rules.

Usage

pepperlint -include-pkgs="github.com/aws/aws-sdk-go" ./main.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Log func(format string, args ...interface{})

Log will be used to log only if PEPPERLINT_DEBUG is set

Functions

func GetImportPathFromFullPath

func GetImportPathFromFullPath(path string) string

GetImportPathFromFullPath will return the import path from the given full path

func GetOpFromType

func GetOpFromType(spec *ast.TypeSpec, name string) *ast.CallExpr

GetOpFromType will iterate and find the field of name 'name'. Once that field has been found, it will return the call expr. If that field is not found, nil will be returned

func GetPackageNameFromImportPath

func GetPackageNameFromImportPath(importPath string) string

GetPackageNameFromImportPath will return the package name from the import path

func IsMethod

func IsMethod(expr ast.Decl) bool

IsMethod will return whether or not something is a method.

Types

type ArrayTypeRule

type ArrayTypeRule interface {
	ValidateArrayType(*ast.ArrayType) error
}

ArrayTypeRule represents an interface that will allow for validation to occur on an ast.ArrayType.

type ArrayTypeRules

type ArrayTypeRules []ArrayTypeRule

ArrayTypeRules is a list of type ArrayTypeRule.

func (ArrayTypeRules) ValidateArrayType

func (rules ArrayTypeRules) ValidateArrayType(array *ast.ArrayType) error

ValidateArrayType will iterate through the list of array types and call ValidateArrayType. If an error is returned, then that error will be added to the batch of errors.

type AssignStmtRule

type AssignStmtRule interface {
	ValidateAssignStmt(*ast.AssignStmt) error
}

AssignStmtRule represents an interface that will allow for validation to occur on an ast.AssignStmt.

type AssignStmtRules

type AssignStmtRules []AssignStmtRule

AssignStmtRules is a list of type AssignStmtRule.

func (AssignStmtRules) ValidateAssignStmt

func (rules AssignStmtRules) ValidateAssignStmt(stmt *ast.AssignStmt) error

ValidateAssignStmt will iterate through the list of array types and call ValidateAssignStmt. If an error is returned, then that error will be added to the batch of errors.

type BatchError

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

BatchError groups a set of errors together usually to organize them by Validator but is not limited to.

func NewBatchError

func NewBatchError(errs ...error) *BatchError

NewBatchError returns a new BatchError

func (*BatchError) Add

func (e *BatchError) Add(errs ...error)

Add will add a new error to the BatchError

func (BatchError) Error

func (e BatchError) Error() string

func (*BatchError) Errors

func (e *BatchError) Errors() []error

Errors returns the list of errors back

func (*BatchError) Len

func (e *BatchError) Len() int

Len returns the length of the errors contained in the BatchError

func (*BatchError) Return

func (e *BatchError) Return() error

Return will return BatchError if there is at least 1 error in the container. If not, nil will be returned

type BinaryExprRule

type BinaryExprRule interface {
	ValidateBinaryExpr(*ast.BinaryExpr) error
}

BinaryExprRule represents an interface that will allow for validation to occur on an ast.BinaryExpr.

type BinaryExprRules

type BinaryExprRules []BinaryExprRule

BinaryExprRules is a list of type BinaryExprRule.

func (BinaryExprRules) ValidateBinaryExpr

func (rules BinaryExprRules) ValidateBinaryExpr(fn *ast.BinaryExpr) error

ValidateBinaryExpr will iterate through the list of array types and call ValidateBinaryExpr. If an error is returned, then that error will be added to the batch of errors.

type BlockStmtRule

type BlockStmtRule interface {
	ValidateBlockStmt(*ast.BlockStmt) error
}

BlockStmtRule represents an interface that will allow for validation to occur on an ast.BlockStmt.

type BlockStmtRules

type BlockStmtRules []BlockStmtRule

BlockStmtRules is a list of type BlockStmtRule.

func (BlockStmtRules) ValidateBlockStmt

func (rules BlockStmtRules) ValidateBlockStmt(stmt *ast.BlockStmt) error

ValidateBlockStmt will iterate through the list of array types and call ValidateBlockStmt. If an error is returned, then that error will be added to the batch of errors.

type Cache

type Cache struct {
	Packages             Packages
	CurrentPkgImportPath string
	CurrentASTFile       *ast.File
}

Cache defintion that contain type information per package.

func NewCache

func NewCache() *Cache

NewCache will return a new cache along with initializing any fields.

func (Cache) CurrentFile

func (c Cache) CurrentFile() (*File, bool)

CurrentFile will attempt to return the current file that is being visited. If the file could not be found, then false will be returned.

func (Cache) CurrentPackage

func (c Cache) CurrentPackage() (*Package, bool)

CurrentPackage will attempt to return the current package. If CurrentPkgImportPath was not found in the map, then false will be returned.

func (*Cache) Visit

func (c *Cache) Visit(node ast.Node) ast.Visitor

Visit will cache all specifications and docs

type CacheOption

type CacheOption interface {
	WithCache(*Cache)
}

CacheOption will allow rules to perform action based on what is in the cache.

type CallExprRule

type CallExprRule interface {
	ValidateCallExpr(*ast.CallExpr) error
}

CallExprRule represents an interface that will allow for validation to occur on an ast.CallExpr.

type CallExprRules

type CallExprRules []CallExprRule

CallExprRules is a list of type CallExprRule.

func (CallExprRules) ValidateCallExpr

func (rules CallExprRules) ValidateCallExpr(expr *ast.CallExpr) error

ValidateCallExpr will iterate through the list of array types and call ValidateCallExpr. If an error is returned, then that error will be added to the batch of errors.

type ChanTypeRule

type ChanTypeRule interface {
	ValidateChanType(*ast.ChanType) error
}

ChanTypeRule represents an interface that will allow for validation to occur on an ast.ChanType.

type ChanTypeRules

type ChanTypeRules []ChanTypeRule

ChanTypeRules is a list of type ChanTypeRule.

func (ChanTypeRules) ValidateChanType

func (rules ChanTypeRules) ValidateChanType(ch *ast.ChanType) error

ValidateChanType will iterate through the list of array types and call ValidateChanType. If an error is returned, then that error will be added to the batch of errors.

type CopyRuler

type CopyRuler interface {
	CopyRule() Rule
}

CopyRuler is used to copy a pre-existing rule allowing for a new rule to be acted upon indenpendently from the rule it is copied from.

type ErrorWrap

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

ErrorWrap will extract the line number from the ast.Node provided. The prefix usually represents the file name that the lint error was found in.

func NewErrorWrap

func NewErrorWrap(fset *token.FileSet, node ast.Node, msg string) *ErrorWrap

NewErrorWrap will return a new error and construct a prefix based on the node and file set. TODO: Wrap all returned errors in visitor.go with line number and file name

func (*ErrorWrap) Error

func (e *ErrorWrap) Error() string

func (*ErrorWrap) Filename

func (e *ErrorWrap) Filename() string

Filename will return the filename of where the error occurred

func (*ErrorWrap) LineNumber

func (e *ErrorWrap) LineNumber() int

LineNumber return the line number to which the error occurred

type Errors

type Errors []error

Errors is a list of errors. This type is mostly used for pretty printing the error message.

func (*Errors) Add

func (e *Errors) Add(errs ...error)

Add will add the series of errors to the list.

func (Errors) Count

func (e Errors) Count() int

Count will return the number of errors in the list. If there are any batch error, this will make recursive calls until a non-batch error is found.

func (Errors) Error

func (e Errors) Error() string

type FieldListRule

type FieldListRule interface {
	ValidateFieldList(*ast.FieldList) error
}

FieldListRule represents an interface that will allow for validation to occur on an ast.FieldList.

type FieldListRules

type FieldListRules []FieldListRule

FieldListRules is a list of type FieldListRule.

func (FieldListRules) ValidateFieldList

func (rules FieldListRules) ValidateFieldList(fields *ast.FieldList) error

ValidateFieldList will iterate through the list of array types and call ValidateFieldList. If an error is returned, then that error will be added to the batch of errors.

type FieldRule

type FieldRule interface {
	ValidateField(*ast.Field) error
}

FieldRule represents an interface that will allow for validation to occur on an ast.Field.

type FieldRules

type FieldRules []FieldRule

FieldRules is a list of type FieldRule.

func (FieldRules) ValidateField

func (rules FieldRules) ValidateField(field *ast.Field) error

ValidateField will iterate through the list of array types and call ValidateField. If an error is returned, then that error will be added to the batch of errors.

type File

type File struct {
	ASTFile   *ast.File
	TypeInfos TypeInfos
	OpInfos   OpInfos

	Imports map[string]string
}

File contains the file scope of types and operation infos

func NewFile

func NewFile(t *ast.File) *File

NewFile will return a new file with any instantiation that needs to be done.

type FileError

type FileError interface {
	error

	LineNumber
	Filename
}

FileError is an error interface that will represent an error and where it occurred.

type FileRule

type FileRule interface {
	ValidateFile(*ast.File) error
}

FileRule represents an interface that will allow for validation to occur on an ast.File.

type FileRules

type FileRules []FileRule

FileRules is a list of type FileRule.

func (FileRules) ValidateFile

func (rules FileRules) ValidateFile(stmt *ast.File) error

ValidateFile will iterate through the list of array types and call ValidateFile. If an error is returned, then that error will be added to the batch of errors.

type FileSetOption

type FileSetOption interface {
	WithFileSet(*token.FileSet)
}

FileSetOption will set the token.FileSet to a given rule.

type Filename

type Filename interface {
	Filename() string
}

Filename is the filename of where the error occurred.

type Files

type Files []*File

Files is a list of Files

func (Files) GetOpInfo

func (fs Files) GetOpInfo(opName string) (OpInfo, bool)

GetOpInfo will iterate through all the files in an atttempt to grab the specified op info by the op name provided.

func (Files) GetTypeInfo

func (fs Files) GetTypeInfo(typeName string) (TypeInfo, bool)

GetTypeInfo will iterate through all the files in an attempt to grab the specified type info by type name provided.

type FuncDeclRule

type FuncDeclRule interface {
	ValidateFuncDecl(*ast.FuncDecl) error
}

FuncDeclRule represents an interface that will allow for validation to occur on an ast.FuncDecl.

type FuncDeclRules

type FuncDeclRules []FuncDeclRule

FuncDeclRules is a list of type FuncDeclRule.

func (FuncDeclRules) ValidateFuncDecl

func (rules FuncDeclRules) ValidateFuncDecl(decl *ast.FuncDecl) error

ValidateFuncDecl will iterate through the list of array types and call ValidateFuncDecl. If an error is returned, then that error will be added to the batch of errors.

type FuncTypeRule

type FuncTypeRule interface {
	ValidateFuncType(*ast.FuncType) error
}

FuncTypeRule represents an interface that will allow for validation to occur on an ast.FuncType.

type FuncTypeRules

type FuncTypeRules []FuncTypeRule

FuncTypeRules is a list of type FuncTypeRule.

func (FuncTypeRules) ValidateFuncType

func (rules FuncTypeRules) ValidateFuncType(fn *ast.FuncType) error

ValidateFuncType will iterate through the list of array types and call ValidateFuncType. If an error is returned, then that error will be added to the batch of errors.

type GenDeclRule

type GenDeclRule interface {
	ValidateGenDecl(*ast.GenDecl) error
}

GenDeclRule represents an interface that will allow for validation to occur on an ast.GenDecl.

type GenDeclRules

type GenDeclRules []GenDeclRule

GenDeclRules is a list of type GenDeclRule.

func (GenDeclRules) ValidateGenDecl

func (rules GenDeclRules) ValidateGenDecl(decl *ast.GenDecl) error

ValidateGenDecl will iterate through the list of array types and call ValidateGenDecl. If an error is returned, then that error will be added to the batch of errors.

type Helper

type Helper struct {
	PackagesCache *Cache
}

Helper is used to make determing properties of an ast.Node

func NewHelper

func NewHelper(cache *Cache) Helper

NewHelper will return a new helper with a populated cache.

func (Helper) GetFieldByIndex

func (h Helper) GetFieldByIndex(index int, spec *ast.TypeSpec) *ast.Field

GetFieldByIndex will retrieve the ast.Field off of an ast.TypeSpec and field index.

func (Helper) GetFieldByName

func (h Helper) GetFieldByName(fieldName string, spec *ast.TypeSpec) *ast.Field

GetFieldByName will retrieve the ast.Field off of an ast.TypeSpec and field name.

func (Helper) GetStructName

func (h Helper) GetStructName(expr ast.Expr) string

GetStructName will return a struct from the given expr.

func (Helper) GetStructType

func (h Helper) GetStructType(expr ast.Expr) *ast.StructType

GetStructType will return a struct from the given expr.

func (Helper) GetTypeSpec

func (h Helper) GetTypeSpec(expr ast.Expr) *ast.TypeSpec

GetTypeSpec will return the given type spec for an expression. nil will be returned if one could not be found

func (Helper) IsStruct

func (h Helper) IsStruct(expr ast.Expr) bool

IsStruct will return whether or not an ast.Expr is a struct type.

type IncDecStmtRule

type IncDecStmtRule interface {
	ValidateIncDecStmt(*ast.IncDecStmt) error
}

IncDecStmtRule represents an interface that will allow for validation to occur on an ast.IncDecStmt.

type IncDecStmtRules

type IncDecStmtRules []IncDecStmtRule

IncDecStmtRules is a list of type IncDecStmtRule.

func (IncDecStmtRules) ValidateIncDecStmt

func (rules IncDecStmtRules) ValidateIncDecStmt(fn *ast.IncDecStmt) error

ValidateIncDecStmt will iterate through the list of array types and call ValidateIncDecStmt. If an error is returned, then that error will be added to the batch of errors.

type InterfaceTypeRule

type InterfaceTypeRule interface {
	ValidateInterfaceType(*ast.InterfaceType) error
}

InterfaceTypeRule represents an interface that will allow for validation to occur on an ast.InterfaceType.

type InterfaceTypeRules

type InterfaceTypeRules []InterfaceTypeRule

InterfaceTypeRules is a list of type InterfaceTypeRule.

func (InterfaceTypeRules) ValidateInterfaceType

func (rules InterfaceTypeRules) ValidateInterfaceType(iface *ast.InterfaceType) error

ValidateInterfaceType will iterate through the list of array types and call ValidateInterfaceType. If an error is returned, then that error will be added to the batch of errors.

type LineNumber

type LineNumber interface {
	LineNumber() int
}

LineNumber is used to return a line number of where an error occurred.

type MapTypeRule

type MapTypeRule interface {
	ValidateMapType(*ast.MapType) error
}

MapTypeRule represents an interface that will allow for validation to occur on an ast.MapType.

type MapTypeRules

type MapTypeRules []MapTypeRule

MapTypeRules is a list of type MapTypeRule.

func (MapTypeRules) ValidateMapType

func (rules MapTypeRules) ValidateMapType(m *ast.MapType) error

ValidateMapType will iterate through the list of array types and call ValidateMapType. If an error is returned, then that error will be added to the batch of errors.

type OpInfo

type OpInfo struct {
	IsMethod  bool
	TypeSpecs []*ast.TypeSpec
	Decl      *ast.FuncDecl
	PkgName   string
}

OpInfo signifies an operation which is a method or function.

func (OpInfo) HasReceiverType

func (oi OpInfo) HasReceiverType(spec *ast.TypeSpec) bool

HasReceiverType will return true if the method has a receiver of type spec.

type OpInfos

type OpInfos map[string]OpInfo

OpInfos is a map of key operation name and OpInfo containing relevant per package operation declarations.

type Option

type Option interface{}

Option will allow rules to be prepped with defined visitor Rules or caching can be initialized during the 'With' call of the option

type Package

type Package struct {
	Name  string
	Files Files
}

Package is a container for a list of files

type PackageRule

type PackageRule interface {
	ValidatePackage(*ast.Package) error
}

PackageRule represents an interface that will allow for validation to occur on an ast.Package.

type PackageRules

type PackageRules []PackageRule

PackageRules is a list of type PackageRule.

func (PackageRules) ValidatePackage

func (rules PackageRules) ValidatePackage(pkg *ast.Package) error

ValidatePackage will iterate through the list of array types and call ValidatePackage. If an error is returned, then that error will be added to the batch of errors.

type Packages

type Packages map[string]*Package

Packages is a map of Packages that keyed off of the import path.

func (Packages) Get

func (p Packages) Get(pkg string) (*Package, bool)

Get attempts to grab the package by name and return it if it exists.

type RangeStmtRule

type RangeStmtRule interface {
	ValidateRangeStmt(*ast.RangeStmt) error
}

RangeStmtRule represents an interface that will allow for validation to occur on an ast.RangeStmt.

type RangeStmtRules

type RangeStmtRules []RangeStmtRule

RangeStmtRules is a list of type RangeStmtRule.

func (RangeStmtRules) ValidateRangeStmt

func (rules RangeStmtRules) ValidateRangeStmt(stmt *ast.RangeStmt) error

ValidateRangeStmt will iterate through the list of array types and call ValidateRangeStmt. If an error is returned, then that error will be added to the batch of errors.

type ReturnStmtRule

type ReturnStmtRule interface {
	ValidateReturnStmt(*ast.ReturnStmt) error
}

ReturnStmtRule represents an interface that will allow for validation to occur on an ast.ReturnStmt.

type ReturnStmtRules

type ReturnStmtRules []ReturnStmtRule

ReturnStmtRules is a list of type ReturnStmtRule.

func (ReturnStmtRules) ValidateReturnStmt

func (rules ReturnStmtRules) ValidateReturnStmt(stmt *ast.ReturnStmt) error

ValidateReturnStmt will iterate through the list of array types and call ValidateReturnStmt. If an error is returned, then that error will be added to the batch of errors.

type Rule

type Rule interface{}

Rule is an empty interface but will allow for modifications later if this needs to be a more specific type.

type Rules

type Rules struct {
	PackageRules PackageRules
	FileRules    FileRules

	// Specifications
	TypeSpecRules  TypeSpecRules
	ValueSpecRules ValueSpecRules

	// Declarations
	GenDeclRules  GenDeclRules
	FuncDeclRules FuncDeclRules

	// Expressions
	CallExprRules   CallExprRules
	BinaryExprRules BinaryExprRules

	// Statements
	AssignStmtRules AssignStmtRules
	BlockStmtRules  BlockStmtRules
	ReturnStmtRules ReturnStmtRules
	IncDecStmtRules IncDecStmtRules
	RangeStmtRules  RangeStmtRules

	// Complex Types
	StructTypeRules    StructTypeRules
	FieldRules         FieldRules
	FieldListRules     FieldListRules
	FuncTypeRules      FuncTypeRules
	InterfaceTypeRules InterfaceTypeRules

	// Container Types
	ArrayTypeRules ArrayTypeRules
	ChanTypeRules  ChanTypeRules
	MapTypeRules   MapTypeRules
}

Rules contain a set of all rule types that will be ran during visitation.

func (*Rules) Merge

func (r *Rules) Merge(otherRules Rules) *Rules

Merge will merge two rule sets together.

type RulesAdder

type RulesAdder interface {
	AddRules(*Rules)
}

RulesAdder will add rules to sets of rules

type StructTypeRule

type StructTypeRule interface {
	ValidateStructType(*ast.StructType) error
}

StructTypeRule allows for rules to be handled on ast.StructType definitions

type StructTypeRules

type StructTypeRules []StructTypeRule

StructTypeRules is a list of type StructTypeRule

func (StructTypeRules) ValidateStructType

func (rules StructTypeRules) ValidateStructType(s *ast.StructType) error

ValidateStructType will iterate through all provided StructTypeRules and call the ValidateStructType. Errors will be added in the BatchError type

type TypeInfo

type TypeInfo struct {
	Doc     *ast.CommentGroup
	Spec    *ast.TypeSpec
	PkgName string
}

TypeInfo contains the type definition and documentation tied to that definition.

type TypeInfos

type TypeInfos map[string]TypeInfo

TypeInfos represents a map of TypeInfos

type TypeSpecRule

type TypeSpecRule interface {
	ValidateTypeSpec(*ast.TypeSpec) error
}

TypeSpecRule represents an interface that will allow for validation to occur on an ast.TypeSpec.

type TypeSpecRules

type TypeSpecRules []TypeSpecRule

TypeSpecRules is a list of type TypeSpecRule.

func (TypeSpecRules) ValidateTypeSpec

func (rules TypeSpecRules) ValidateTypeSpec(spec *ast.TypeSpec) error

ValidateTypeSpec will iterate through the list of array types and call ValidateTypeSpec. If an error is returned, then that error will be added to the batch of errors.

type ValueSpecRule

type ValueSpecRule interface {
	ValidateValueSpec(*ast.ValueSpec) error
}

ValueSpecRule represents an interface that will allow for validation to occur on an ast.ValueSpec.

type ValueSpecRules

type ValueSpecRules []ValueSpecRule

ValueSpecRules is a list of type ValueSpecRule.

func (ValueSpecRules) ValidateValueSpec

func (rules ValueSpecRules) ValidateValueSpec(spec *ast.ValueSpec) error

ValidateValueSpec will iterate through the list of array types and call ValidateValueSpec. If an error is returned, then that error will be added to the batch of errors.

type Visitor

type Visitor struct {
	Rules  Rules
	Errors Errors

	PackagesCache *Cache

	FileSet *token.FileSet
	// contains filtered or unexported fields
}

Visitor is used to traferse a node and run the proper validaters based on the node that is passed in.

func NewVisitor

func NewVisitor(fset *token.FileSet, cache *Cache, opts ...Option) *Visitor

NewVisitor returns a new visitor and instantiates a new rule set from the adders parameter.

func (*Visitor) Visit

func (v *Visitor) Visit(node ast.Node) ast.Visitor

Visit is our generic visitor that will visit each ast type and call the appropriate rules based on what type the node is.

Directories

Path Synopsis
cmd
aws

Jump to

Keyboard shortcuts

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