lint

package
v0.0.0-...-e2e2fe3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package lint provides the foundation for tools like gosimple.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportedType

func ExportedType(typ types.Type) bool

exportedType reports whether typ is an exported type. It is imprecise, and will err on the side of returning true, such as for composite types.

func ExprToInt

func ExprToInt(expr ast.Expr) (string, bool)

func IsBlank

func IsBlank(id ast.Expr) bool

isBlank returns whether id is the blank identifier "_". If id == nil, the answer is false.

func IsIdent

func IsIdent(expr ast.Expr, ident string) bool

func IsNil

func IsNil(expr ast.Expr) bool

func IsOne

func IsOne(expr ast.Expr) bool

func IsPkgDot

func IsPkgDot(expr ast.Expr, pkg, name string) bool

func IsZero

func IsZero(expr ast.Expr) bool

func ReceiverType

func ReceiverType(fn *ast.FuncDecl) string

func SrcLine

func SrcLine(src []byte, p token.Position) string

srcLine returns the complete line at p, including the terminating newline.

Types

type ByPosition

type ByPosition []Problem

func (ByPosition) Len

func (p ByPosition) Len() int

func (ByPosition) Less

func (p ByPosition) Less(i, j int) bool

func (ByPosition) Swap

func (p ByPosition) Swap(i, j int)

type Category

type Category string

type File

type File struct {
	Pkg      *Pkg
	File     *ast.File
	Fset     *token.FileSet
	Src      []byte
	Filename string
}

file represents a file being linted.

func (*File) BoolConst

func (f *File) BoolConst(expr ast.Expr) bool

func (*File) Errorf

func (f *File) Errorf(n ast.Node, confidence float64, args ...interface{}) *Problem

The variadic arguments may start with link and category types, and must end with a format string and any arguments. It returns the new Problem.

func (*File) FirstLineOf

func (f *File) FirstLineOf(node, match ast.Node) string

firstLineOf renders the given node and returns its first line. It will also match the indentation of another node.

func (*File) IndentOf

func (f *File) IndentOf(node ast.Node) string

func (*File) IsBoolConst

func (f *File) IsBoolConst(expr ast.Expr) bool

func (*File) IsMain

func (f *File) IsMain() bool

func (*File) IsTest

func (f *File) IsTest() bool

func (*File) IsUntypedConst

func (f *File) IsUntypedConst(expr ast.Expr) (defType string, ok bool)

isUntypedConst reports whether expr is an untyped constant, and indicates what its default type is. scope may be nil.

func (*File) Render

func (f *File) Render(x interface{}) string

func (*File) RenderArgs

func (f *File) RenderArgs(args []ast.Expr) string

func (*File) SrcLineWithMatch

func (f *File) SrcLineWithMatch(node ast.Node, pattern string) (m []string)

func (*File) Walk

func (f *File) Walk(fn func(ast.Node) bool)

type Func

type Func func(*File)
type Link string

type Linter

type Linter struct {
	Funcs []Func
}

A Linter lints Go source code.

func (*Linter) Lint

func (l *Linter) Lint(filename string, src []byte) ([]Problem, error)

Lint lints src.

func (*Linter) LintFiles

func (l *Linter) LintFiles(files map[string][]byte) ([]Problem, error)

LintFiles lints a set of files of a single package. The argument is a map of filename to source.

type Pkg

type Pkg struct {
	TypesPkg  *types.Package
	TypesInfo *types.Info
	// contains filtered or unexported fields
}

pkg represents a package being linted.

func (*Pkg) ErrorfAt

func (p *Pkg) ErrorfAt(pos token.Position, confidence float64, args ...interface{}) *Problem

func (*Pkg) IsMain

func (p *Pkg) IsMain() bool

func (*Pkg) IsNamedType

func (p *Pkg) IsNamedType(typ types.Type, importPath, name string) bool

func (*Pkg) ScopeOf

func (p *Pkg) ScopeOf(id *ast.Ident) *types.Scope

scopeOf returns the tightest scope encompassing id.

type Problem

type Problem struct {
	Position   token.Position // position in source file
	Text       string         // the prose that describes the problem
	Link       string         // (optional) the link to the style guide for the problem
	Confidence float64        // a value in (0,1] estimating the confidence in this problem's correctness
	LineText   string         // the source line
	Category   string         // a short name for the general category of the problem

	// If the problem has a suggested fix (the minority case),
	// ReplacementLine is a full replacement for the relevant line of the source file.
	ReplacementLine string
}

Problem represents a problem in some source code.

func (*Problem) String

func (p *Problem) String() string

Directories

Path Synopsis
Package lintutil provides helpers for writing linter command lines.
Package lintutil provides helpers for writing linter command lines.

Jump to

Keyboard shortcuts

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