Documentation ¶
Overview ¶
Package lint implements the linting machinery.
Index ¶
- Constants
- func Name(name string, allowlist, blocklist []string) (should string)
- type AbstractRule
- type Arguments
- type Config
- type DirectiveConfig
- type DirectivesConfig
- type DisabledInterval
- type Failure
- type FailurePosition
- type File
- type FileFilter
- type FileFilters
- type Formatter
- type FormatterMetadata
- type Linter
- type Package
- func (p *Package) Files() map[string]*File
- func (p *Package) IsAtLeastGo122() bool
- func (p *Package) IsMain() bool
- func (p *Package) Sortable() map[string]bool
- func (p *Package) TypeCheck() error
- func (p *Package) TypeOf(expr ast.Expr) types.Type
- func (p *Package) TypesInfo() *types.Info
- func (p *Package) TypesPkg() *types.Package
- type ReadFile
- type Rule
- type RuleConfig
- type RulesConfig
- type Severity
Constants ¶
const ( // SeverityWarning declares failures of type warning SeverityWarning = "warning" // SeverityError declares failures of type error. SeverityError = "error" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AbstractRule ¶
type AbstractRule struct {
Failures []Failure
}
AbstractRule defines an abstract rule.
type Config ¶
type Config struct { IgnoreGeneratedHeader bool `toml:"ignoreGeneratedHeader"` Confidence float64 Severity Severity EnableAllRules bool `toml:"enableAllRules"` Rules RulesConfig `toml:"rule"` ErrorCode int `toml:"errorCode"` WarningCode int `toml:"warningCode"` Directives DirectivesConfig `toml:"directive"` Exclude []string `toml:"exclude"` // If set, overrides the go language version specified in go.mod of // packages being linted, and assumes this specific language version. GoVersion *goversion.Version }
Config defines the config of the linter.
type DirectiveConfig ¶
type DirectiveConfig struct {
Severity Severity
}
DirectiveConfig is type used for the linter directive configuration.
type DirectivesConfig ¶
type DirectivesConfig = map[string]DirectiveConfig
DirectivesConfig defines the config for all directives.
type DisabledInterval ¶
DisabledInterval contains a single disabled interval and the associated rule name.
type Failure ¶
type Failure struct { Failure string RuleName string Category string Position FailurePosition Node ast.Node `json:"-"` Confidence float64 // For future use ReplacementLine string }
Failure defines a struct for a linting failure.
func (*Failure) GetFilename ¶
GetFilename returns the filename.
type FailurePosition ¶
FailurePosition returns the failure position
func ToFailurePosition ¶
func ToFailurePosition(start, end token.Pos, file *File) FailurePosition
ToFailurePosition returns the failure position.
type File ¶
type File struct { Name string Pkg *Package AST *ast.File // contains filtered or unexported fields }
File abstraction used for representing files.
func (*File) CommentMap ¶
func (f *File) CommentMap() ast.CommentMap
CommentMap builds a comment map for the file.
func (*File) IsUntypedConst ¶
IsUntypedConst reports whether expr is an untyped constant, and indicates what its default type is. scope may be nil.
type FileFilter ¶ added in v1.3.9
type FileFilter struct {
// contains filtered or unexported fields
}
FileFilter - file filter to exclude some files for rule supports whole 1. file/dir names : pkg/mypkg/my.go, 2. globs: **/*.pb.go, 3. regexes (~ prefix) ~-tmp\.\d+\.go 4. special test marker `TEST` - treats as `~_test\.go`
func ParseFileFilter ¶ added in v1.3.9
func ParseFileFilter(rawFilter string) (*FileFilter, error)
ParseFileFilter - creates FileFilter for given raw filter if empty string, it matches nothing if `*`, or `~`, it matches everything while regexp could be invalid, it could return it's compilation error
func (*FileFilter) MatchFileName ¶ added in v1.3.9
func (ff *FileFilter) MatchFileName(name string) bool
MatchFileName - checks if file name matches filter
func (*FileFilter) String ¶ added in v1.3.9
func (ff *FileFilter) String() string
type FileFilters ¶ added in v1.3.9
type FileFilters = []*FileFilter
FileFilters is type used for modeling file filters to apply to rules.
type FormatterMetadata ¶
FormatterMetadata configuration of a formatter
type Linter ¶
type Linter struct {
// contains filtered or unexported fields
}
Linter is used for linting set of files.
type Package ¶
Package represents a package in the project.
func (*Package) IsAtLeastGo122 ¶ added in v1.3.9
IsAtLeastGo122 returns true if the Go version for this package is 1.22 or higher, false otherwise
type RuleConfig ¶
type RuleConfig struct { Arguments Arguments Severity Severity Disabled bool // Exclude - rule-level file excludes, TOML related (strings) Exclude []string // contains filtered or unexported fields }
RuleConfig is type used for the rule configuration.
func (*RuleConfig) Initialize ¶ added in v1.3.9
func (rc *RuleConfig) Initialize() error
Initialize - should be called after reading from TOML file
func (*RuleConfig) MustExclude ¶ added in v1.3.9
func (rc *RuleConfig) MustExclude(name string) bool
MustExclude - checks if given filename `name` must be excluded
type RulesConfig ¶
type RulesConfig = map[string]RuleConfig
RulesConfig defines the config for all rules.