Documentation
¶
Overview ¶
Package lint implements the linting machinery.
Index ¶
- Constants
- Variables
- func Name(name string, allowlist, blocklist []string) stringdeprecated
- type Arguments
- type Config
- type ConfigurableRule
- type DirectiveConfig
- type DirectivesConfig
- type DisabledInterval
- type Failure
- type FailureCategory
- type FailurePosition
- type File
- func (f *File) CommentMap() ast.CommentMap
- func (f *File) Content() []byte
- func (f *File) IsImportable() bool
- func (f *File) IsTest() bool
- func (f *File) IsUntypedConst(expr ast.Expr) (defType string, ok bool)
- func (f *File) Render(x any) string
- func (f *File) ToPosition(pos token.Pos) token.Position
- type FileFilter
- type FileFilters
- type Formatter
- type FormatterMetadata
- type Linter
- type Package
- func (p *Package) Files() map[string]*File
- func (p *Package) IsAtLeastGoVersion(v *goversion.Version) 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 ¶
var ( // Go115 is a constant representing the Go version 1.15. Go115 = goversion.Must(goversion.NewVersion("1.15")) // Go121 is a constant representing the Go version 1.21. Go121 = goversion.Must(goversion.NewVersion("1.21")) // Go122 is a constant representing the Go version 1.22. Go122 = goversion.Must(goversion.NewVersion("1.22")) // Go124 is a constant representing the Go version 1.24. Go124 = goversion.Must(goversion.NewVersion("1.24")) // Go125 is a constant representing the Go version 1.25. Go125 = goversion.Must(goversion.NewVersion("1.25")) )
Functions ¶
Types ¶
type Config ¶
type Config struct {
IgnoreGeneratedHeader bool `toml:"ignoreGeneratedHeader"`
Confidence float64 `toml:"confidence"`
Severity Severity `toml:"severity"`
EnableAllRules bool `toml:"enableAllRules"`
EnableDefaultRules bool `toml:"enableDefaultRules"`
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 `toml:"goVersion"`
}
Config defines the config of the linter.
type ConfigurableRule ¶ added in v1.6.0
ConfigurableRule defines an abstract configurable rule interface.
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 `json:"Failure"`
RuleName string `json:"RuleName"`
Category FailureCategory `json:"Category"`
Position FailurePosition `json:"Position"`
Node ast.Node `json:"-"`
Confidence float64 `json:"Confidence"`
ReplacementLine string `json:"ReplacementLine"`
}
Failure defines a struct for a linting failure.
func NewInternalFailure ¶ added in v1.6.0
NewInternalFailure yields an internal failure with the given message as failure message.
func (*Failure) GetFilename
deprecated
GetFilename returns the filename.
Deprecated: Use Failure.Filename instead.
func (*Failure) IsInternal ¶ added in v1.6.0
IsInternal returns true if this failure is internal, false otherwise.
type FailureCategory ¶ added in v1.6.0
type FailureCategory string
FailureCategory is the type for the failure categories.
const ( // FailureCategoryArgOrder indicates argument order issues. FailureCategoryArgOrder FailureCategory = "arg-order" // FailureCategoryBadPractice indicates bad practice issues. FailureCategoryBadPractice FailureCategory = "bad practice" // FailureCategoryCodeStyle indicates code style issues. // // Deprecated: use FailureCategoryStyle instead. FailureCategoryCodeStyle FailureCategory = "code-style" // FailureCategoryComments indicates comment issues. FailureCategoryComments FailureCategory = "comments" // FailureCategoryComplexity indicates complexity issues. FailureCategoryComplexity FailureCategory = "complexity" // FailureCategoryContent indicates content issues. FailureCategoryContent FailureCategory = "content" // FailureCategoryErrors indicates error handling issues. FailureCategoryErrors FailureCategory = "errors" // FailureCategoryImports indicates import issues. FailureCategoryImports FailureCategory = "imports" // FailureCategoryLogic indicates logic issues. FailureCategoryLogic FailureCategory = "logic" // FailureCategoryMaintenance indicates maintenance issues. FailureCategoryMaintenance FailureCategory = "maintenance" // FailureCategoryNaming indicates naming issues. FailureCategoryNaming FailureCategory = "naming" // FailureCategoryOptimization indicates optimization issues. FailureCategoryOptimization FailureCategory = "optimization" // FailureCategoryStyle indicates style issues. FailureCategoryStyle FailureCategory = "style" // FailureCategoryTime indicates time-related issues. FailureCategoryTime FailureCategory = "time" // FailureCategoryTypeInference indicates type inference issues. FailureCategoryTypeInference FailureCategory = "type-inference" // FailureCategoryUnaryOp indicates unary operation issues. FailureCategoryUnaryOp FailureCategory = "unary-op" // FailureCategoryUnexportedTypeInAPI indicates unexported type in API issues. FailureCategoryUnexportedTypeInAPI FailureCategory = "unexported-type-in-api" // FailureCategoryZeroValue indicates zero value issues. FailureCategoryZeroValue FailureCategory = "zero-value" )
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) IsImportable ¶ added in v1.11.0
IsImportable returns if the symbols defined in this file can be imported in other packages.
Symbols from the package `main` or test files are not exported, so they cannot be imported.
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.3
type FileFilter struct {
// contains filtered or unexported fields
}
FileFilter filters file to exclude some files for a rule. Supports the following:
- File or directory names: pkg/mypkg/my.go
- Globs: **/*.pb.go,
- Regexes (with ~ prefix): ~-tmp\.\d+\.go
- Special test marker `TEST` (treated as `~_test\.go`).
func ParseFileFilter ¶ added in v1.3.3
func ParseFileFilter(rawFilter string) (*FileFilter, error)
ParseFileFilter creates a FileFilter for the given raw filter. If the string is empty, it matches nothing. If the string is `*` or `~`, it matches everything. If the regular expression is invalid, it returns a compilation error.
func (*FileFilter) MatchFileName ¶ added in v1.3.3
func (ff *FileFilter) MatchFileName(name string) bool
MatchFileName checks if the file name matches the filter.
func (*FileFilter) String ¶ added in v1.3.3
func (ff *FileFilter) String() string
String returns the original raw filter definition as it appears in the configuration.
type FileFilters ¶ added in v1.3.3
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 ¶
type Package struct {
// contains filtered or unexported fields
}
Package represents a package in the project.
func (*Package) IsAtLeastGoVersion ¶ added in v1.8.0
IsAtLeastGoVersion returns true if the Go version for this package is v or higher, false otherwise.
type RuleConfig ¶
type RuleConfig struct {
Arguments Arguments
Severity Severity
Disabled bool
// Exclude is 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.3
func (rc *RuleConfig) Initialize() error
Initialize should be called after reading from TOML file.
func (*RuleConfig) MustExclude ¶ added in v1.3.3
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.