Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
UnknownType is a special sentinel value that is returned from the CheckerContext.TypeOf method instead of the nil type.
Functions ¶
This section is empty.
Types ¶
type Checker ¶
type Checker struct { // Info is an info object that was used to instantiate this checker. Info *CheckerInfo // contains filtered or unexported fields }
Checker is an implementation of a check that is described by the associated info.
func NewChecker ¶
func NewChecker(ctx *Context, info *CheckerInfo) (*Checker, error)
NewChecker returns initialized checker identified by an info. info must be non-nil. Returns an error if info describes a checker that was not properly registered, or if checker fails to initialize.
type CheckerCollection ¶
type CheckerCollection struct { // URL is a link for a main source of information on the collection. URL string }
CheckerCollection provides additional information for a group of checkers.
func (*CheckerCollection) AddChecker ¶
func (coll *CheckerCollection) AddChecker(info *CheckerInfo, constructor func(*CheckerContext) (FileWalker, error))
AddChecker registers a new checker into a checkers pool. Constructor is used to create a new checker instance. Checker name (defined in CheckerInfo.Name) must be unique.
CheckerInfo.Collection is automatically set to the coll (the receiver).
If checker is never needed, for example if it is disabled, constructor will not be called.
type CheckerContext ¶
type CheckerContext struct { *Context // contains filtered or unexported fields }
CheckerContext is checker-local context copy. Fields that are not from Context itself are writeable.
func (*CheckerContext) TypeOf ¶ added in v0.5.3
func (ctx *CheckerContext) TypeOf(x ast.Expr) types.Type
TypeOf returns the type of expression x.
Unlike TypesInfo.TypeOf, it never returns nil. Instead, it returns the Invalid type as a sentinel UnknownType value.
func (*CheckerContext) Warn ¶
func (ctx *CheckerContext) Warn(node ast.Node, format string, args ...interface{})
Warn adds a Warning to checker output.
func (*CheckerContext) WarnFixable ¶ added in v0.5.8
func (ctx *CheckerContext) WarnFixable(node ast.Node, fix QuickFix, format string, args ...interface{})
WarnFixable emits a warning with a fix suggestion provided by the caller.
type CheckerInfo ¶
type CheckerInfo struct { // Name is a checker name. Name string // Tags is a list of labels that can be used to enable or disable checker. // Common tags are "experimental" and "performance". Tags []string // Params declares checker-specific parameters. Optional. Params CheckerParams // Summary is a short one sentence description. // Should not end with a period. Summary string // Details extends summary with additional info. Optional. Details string // Before is a code snippet of code that will violate rule. Before string // After is a code snippet of fixed code that complies to the rule. After string // Note is an optional caution message or advice. Note string // EmbeddedRuleguard tells whether this checker is auto-generated // from the embedded ruleguard rules. EmbeddedRuleguard bool // Collection establishes a checker-to-collection relationship. Collection *CheckerCollection }
CheckerInfo holds checker metadata and structured documentation.
func GetCheckersInfo ¶
func GetCheckersInfo() []*CheckerInfo
GetCheckersInfo returns a checkers info list for all registered checkers. The slice is sorted by a checker name.
Info objects can be used to instantiate checkers with NewChecker function.
func (*CheckerInfo) HasTag ¶
func (info *CheckerInfo) HasTag(tag string) bool
HasTag reports whether checker described by the info has specified tag.
type CheckerParam ¶
type CheckerParam struct { // Value holds parameter bound value. // It might be overwritten by the integrating linter. // // Permitted types include: // - int // - bool // - string Value interface{} // Usage gives an overview about what parameter does. Usage string }
CheckerParam describes a single checker customizable parameter.
type CheckerParams ¶
type CheckerParams map[string]*CheckerParam
CheckerParams holds all checker-specific parameters.
Provides convenient access to the loosely typed underlying map.
func (CheckerParams) Bool ¶
func (params CheckerParams) Bool(pname string) bool
Bool lookups pname key in underlying map and type-asserts it to bool.
func (CheckerParams) Int ¶
func (params CheckerParams) Int(pname string) int
Int lookups pname key in underlying map and type-asserts it to int.
func (CheckerParams) String ¶
func (params CheckerParams) String(pname string) string
String lookups pname key in underlying map and type-asserts it to string.
type Context ¶
type Context struct { // TypesInfo carries parsed packages types information. TypesInfo *types.Info // SizesInfo carries alignment and type size information. // Arch-dependent. SizesInfo types.Sizes // GoVersion is a target Go version. GoVersion GoVersion // FileSet is a file set that was used during the program loading. FileSet *token.FileSet // Pkg describes package that is being checked. Pkg *types.Package // Filename is a currently checked file name. Filename string // Require records what optional resources are required // by the checkers set that use this context. // // Every require fields makes associated context field // to be properly initialized. // For example, Context.require.PkgObjects => Context.PkgObjects. Require struct { PkgObjects bool PkgRenames bool } // PkgObjects stores all imported packages and their local names. PkgObjects map[*types.PkgName]string // PkgRenames maps package path to its local renaming. // Contains no entries for packages that were imported without // explicit local names. PkgRenames map[string]string }
Context is a readonly state shared among every checker.
func NewContext ¶
NewContext returns new shared context to be used by every checker.
All data carried by the context is readonly for checkers, but can be modified by the integrating application.
func (*Context) SetFileInfo ¶
SetFileInfo sets file-related metadata.
Must be called for every source code file being checked.
func (*Context) SetGoVersion ¶ added in v0.5.8
SetGoVersion adjust the target Go language version.
The format is like "1.5", "1.8", etc. It's permitted to have "go" prefix (e.g. "go1.5").
Empty string (the default) means that we make no Go version assumptions and (like gocritic does) behave like all features are available. To make gocritic more conservative, the upper Go version level should be adjusted.
type FileWalker ¶
FileWalker is an interface every checker should implement.
The WalkFile method is executed for every Go file inside the package that is being checked.
type GoVersion ¶ added in v0.5.8
func ParseGoVersion ¶ added in v0.6.2
func (GoVersion) GreaterOrEqual ¶ added in v0.5.8
GreaterOrEqual performs $v >= $other operation.
In other words, it reports whether $v version constraint can use a feature from the $other Go version.
As a special case, Major=0 covers all versions.
type QuickFix ¶ added in v0.5.8
QuickFix is our analysis.TextEdit; we're using it here to avoid direct analysis package dependency for now.
type Warning ¶
type Warning struct { // Node is an AST node that caused warning to trigger. // Can be used to obtain proper error location. Node ast.Node // Text is warning message without source location info. Text string // Suggestion is a quick fix for a given problem. // QuickFix is analysis.TextEdit and can be used to // construct an analysis.SuggestedFix object. // // For convenience, there is Warning.HasQuickFix() method // that reports whether Suggestion has something meaningful. Suggestion QuickFix }
Warning represents issue that is found by checker.
func (Warning) HasQuickFix ¶ added in v0.5.8
HasQuickFix reports whether this warning has a suggested fix.