Documentation
¶
Index ¶
- Variables
- type Cgo
- type Diff
- type ExclusionPaths
- type ExclusionRules
- type FilenameUnadjuster
- type Fixer
- type GeneratedFileFilter
- type GeneratedFileMatcher
- type InvalidIssue
- type MaxFromLinter
- type MaxPerFileFromLinter
- type MaxSameIssues
- type NolintFilter
- type PathAbsoluter
- type PathPrettifier
- type PathRelativity
- type PathShortener
- type Processor
- type Severity
- type SortResults
- type SourceCode
- type UniqByLine
Constants ¶
This section is empty.
Variables ¶
var LinterExclusionPresets = map[string][]config.ExcludeRule{ config.ExclusionPresetComments: { { BaseRule: config.BaseRule{ Text: "(ST1000|ST1020|ST1021|ST1022)", Linters: []string{"staticcheck"}, InternalReference: "EXC0011", }, }, { BaseRule: config.BaseRule{ Text: `exported (.+) should have comment( \(or a comment on this block\))? or be unexported`, Linters: []string{"revive"}, InternalReference: "EXC0012", }, }, { BaseRule: config.BaseRule{ Text: `package comment should be of the form "(.+)..."`, Linters: []string{"revive"}, InternalReference: "EXC0013", }, }, { BaseRule: config.BaseRule{ Text: `comment on exported (.+) should be of the form "(.+)..."`, Linters: []string{"revive"}, InternalReference: "EXC0014", }, }, { BaseRule: config.BaseRule{ Text: `should have a package comment`, Linters: []string{"revive"}, InternalReference: "EXC0015", }, }, }, config.ExclusionPresetStdErrorHandling: { { BaseRule: config.BaseRule{ Text: "(?i)Error return value of .((os\\.)?std(out|err)\\..*|.*Close" + "|.*Flush|os\\.Remove(All)?|.*print(f|ln)?|os\\.(Un)?Setenv). is not checked", Linters: []string{"errcheck"}, InternalReference: "EXC0001", }, }, }, config.ExclusionPresetCommonFalsePositives: { { BaseRule: config.BaseRule{ Text: "G103: Use of unsafe calls should be audited", Linters: []string{"gosec"}, InternalReference: "EXC0006", }, }, { BaseRule: config.BaseRule{ Text: "G204: Subprocess launched with variable", Linters: []string{"gosec"}, InternalReference: "EXC0007", }, }, { BaseRule: config.BaseRule{ Text: "G304: Potential file inclusion via variable", Linters: []string{"gosec"}, InternalReference: "EXC0010", }, }, }, config.ExclusionPresetLegacy: { { BaseRule: config.BaseRule{ Text: "(possible misuse of unsafe.Pointer|should have signature)", Linters: []string{"govet"}, InternalReference: "EXC0004", }, }, { BaseRule: config.BaseRule{ Text: "SA4011", Linters: []string{"staticcheck"}, InternalReference: "EXC0005", }, }, { BaseRule: config.BaseRule{ Text: "G104", Linters: []string{"gosec"}, InternalReference: "EXC0008", }, }, { BaseRule: config.BaseRule{ Text: "(G301|G302|G307): Expect (directory permissions to be 0750|file permissions to be 0600) or less", Linters: []string{"gosec"}, InternalReference: "EXC0009", }, }, }, }
Functions ¶
This section is empty.
Types ¶
type Cgo ¶
type Cgo struct {
// contains filtered or unexported fields
}
Cgo filters cgo artifacts.
Some linters (e.g. gosec, etc.) return incorrect file paths for cgo files.
Require absolute file path.
type Diff ¶
type Diff struct {
// contains filtered or unexported fields
}
Diff filters issues based on options `new`, `new-from-rev`, etc.
Uses `git`. The paths inside the patch are relative to the path where git is run (the same location where golangci-lint is run).
Warning: it doesn't use `path-prefix` option.
type ExclusionPaths ¶
type ExclusionPaths struct {
// contains filtered or unexported fields
}
func NewExclusionPaths ¶
func NewExclusionPaths(log logutils.Log, cfg *config.LinterExclusions) (*ExclusionPaths, error)
func (*ExclusionPaths) Finish ¶
func (p *ExclusionPaths) Finish()
func (*ExclusionPaths) Name ¶
func (*ExclusionPaths) Name() string
type ExclusionRules ¶
type ExclusionRules struct {
// contains filtered or unexported fields
}
func NewExclusionRules ¶
func NewExclusionRules(log logutils.Log, lines *fsutils.LineCache, cfg *config.LinterExclusions) *ExclusionRules
func (*ExclusionRules) Finish ¶
func (p *ExclusionRules) Finish()
func (*ExclusionRules) Name ¶
func (*ExclusionRules) Name() string
type FilenameUnadjuster ¶
type FilenameUnadjuster struct {
// contains filtered or unexported fields
}
FilenameUnadjuster fixes filename based on adjusted and unadjusted position (related to line directives and cgo).
A lot of linters use `fset.Position(f.Pos())` to get filename, and they return adjusted filename (e.g.` *.qtpl`) for an issue. We need restore real `.go` filename to properly output it, parse it, etc.
Require absolute file path.
func NewFilenameUnadjuster ¶
func NewFilenameUnadjuster(pkgs []*packages.Package, log logutils.Log) *FilenameUnadjuster
func (*FilenameUnadjuster) Finish ¶
func (*FilenameUnadjuster) Finish()
func (*FilenameUnadjuster) Name ¶
func (*FilenameUnadjuster) Name() string
type Fixer ¶
type Fixer struct {
// contains filtered or unexported fields
}
Fixer fixes reports if possible. The reports that are not fixed are passed to the next processor.
type GeneratedFileFilter ¶
type GeneratedFileFilter struct {
// contains filtered or unexported fields
}
GeneratedFileFilter filters generated files.
func NewGeneratedFileFilter ¶
func NewGeneratedFileFilter(mode string) *GeneratedFileFilter
func (*GeneratedFileFilter) Finish ¶
func (*GeneratedFileFilter) Finish()
func (*GeneratedFileFilter) Name ¶
func (*GeneratedFileFilter) Name() string
type GeneratedFileMatcher ¶
type GeneratedFileMatcher struct {
// contains filtered or unexported fields
}
GeneratedFileMatcher detects generated files.
- mode "lax": see `isGeneratedFileLax` documentation.
- mode "strict": see `isGeneratedFileStrict` documentation.
- mode "disable": skips this processor.
func NewGeneratedFileMatcher ¶
func NewGeneratedFileMatcher(mode string) *GeneratedFileMatcher
func (*GeneratedFileMatcher) IsGeneratedFile ¶
func (p *GeneratedFileMatcher) IsGeneratedFile(filepath string, src any) (bool, error)
type InvalidIssue ¶
type InvalidIssue struct {
// contains filtered or unexported fields
}
InvalidIssue filters invalid reports.
- non-go files (except `go.mod`)
- reports without file path
func NewInvalidIssue ¶
func NewInvalidIssue(log logutils.Log) *InvalidIssue
func (InvalidIssue) Finish ¶
func (InvalidIssue) Finish()
func (InvalidIssue) Name ¶
func (InvalidIssue) Name() string
type MaxFromLinter ¶
type MaxFromLinter struct {
// contains filtered or unexported fields
}
MaxFromLinter limits the number of reports from the same linter.
func NewMaxFromLinter ¶
func (*MaxFromLinter) Finish ¶
func (p *MaxFromLinter) Finish()
func (*MaxFromLinter) Name ¶
func (*MaxFromLinter) Name() string
type MaxPerFileFromLinter ¶
type MaxPerFileFromLinter struct {
// contains filtered or unexported fields
}
MaxPerFileFromLinter limits the number of reports by file and by linter.
func NewMaxPerFileFromLinter ¶
func NewMaxPerFileFromLinter(cfg *config.Config) *MaxPerFileFromLinter
func (*MaxPerFileFromLinter) Finish ¶
func (*MaxPerFileFromLinter) Finish()
func (*MaxPerFileFromLinter) Name ¶
func (*MaxPerFileFromLinter) Name() string
type MaxSameIssues ¶
type MaxSameIssues struct {
// contains filtered or unexported fields
}
MaxSameIssues limits the number of reports with the same text.
func NewMaxSameIssues ¶
func (*MaxSameIssues) Finish ¶
func (p *MaxSameIssues) Finish()
func (*MaxSameIssues) Name ¶
func (*MaxSameIssues) Name() string
type NolintFilter ¶
type NolintFilter struct {
// contains filtered or unexported fields
}
NolintFilter filters and sorts reports related to `nolint` directives.
func NewNolintFilter ¶
func (*NolintFilter) Finish ¶
func (p *NolintFilter) Finish()
func (*NolintFilter) Name ¶
func (*NolintFilter) Name() string
type PathAbsoluter ¶
type PathAbsoluter struct {
// contains filtered or unexported fields
}
PathAbsoluter ensures that representation of path are absolute.
func NewPathAbsoluter ¶
func NewPathAbsoluter(log logutils.Log) *PathAbsoluter
func (*PathAbsoluter) Finish ¶
func (*PathAbsoluter) Finish()
func (*PathAbsoluter) Name ¶
func (*PathAbsoluter) Name() string
type PathPrettifier ¶
type PathPrettifier struct {
// contains filtered or unexported fields
}
PathPrettifier modifies report file path to be relative to the base path. Also handles the `output.path-prefix` option.
func NewPathPrettifier ¶
func NewPathPrettifier(log logutils.Log, cfg *config.Output) *PathPrettifier
func (*PathPrettifier) Finish ¶
func (*PathPrettifier) Finish()
func (*PathPrettifier) Name ¶
func (*PathPrettifier) Name() string
type PathRelativity ¶
type PathRelativity struct {
// contains filtered or unexported fields
}
PathRelativity computes result.Issue.RelativePath and result.Issue.WorkingDirectoryRelativePath, based on the base path.
func NewPathRelativity ¶
func NewPathRelativity(log logutils.Log, basePath string) (*PathRelativity, error)
func (*PathRelativity) Finish ¶
func (*PathRelativity) Finish()
func (*PathRelativity) Name ¶
func (*PathRelativity) Name() string
type PathShortener ¶
type PathShortener struct {
// contains filtered or unexported fields
}
PathShortener modifies text of the reports to reduce file path inside the text. It uses the rooted path name corresponding to the current directory (`wd`).
func NewPathShortener ¶
func NewPathShortener() *PathShortener
func (PathShortener) Finish ¶
func (PathShortener) Finish()
func (PathShortener) Name ¶
func (PathShortener) Name() string
type Severity ¶
type Severity struct {
// contains filtered or unexported fields
}
Severity modifies report severity. It uses the same `baseRule` structure as [ExcludeRules] processor.
Warning: it doesn't use `path-prefix` option.
func NewSeverity ¶
type SortResults ¶
type SortResults struct {
// contains filtered or unexported fields
}
SortResults sorts reports based on criteria:
- file names, line numbers, positions
- linter names
- severity names
func NewSortResults ¶
func NewSortResults(cfg *config.Output) *SortResults
func (SortResults) Finish ¶
func (SortResults) Finish()
func (SortResults) Name ¶
func (SortResults) Name() string
type SourceCode ¶
type SourceCode struct {
// contains filtered or unexported fields
}
SourceCode modifies displayed information based on [result.Issue.GetLineRange()].
This is used:
- to display the "UnderLinePointer".
- in some rare cases to display multiple lines instead of one (ex: `dupl`)
It requires to use fsutils.LineCache (fsutils.FileCache) to get the file information before the fixes.
func NewSourceCode ¶
func NewSourceCode(lc *fsutils.LineCache, log logutils.Log) *SourceCode
func (SourceCode) Finish ¶
func (SourceCode) Finish()
func (SourceCode) Name ¶
func (SourceCode) Name() string
type UniqByLine ¶
type UniqByLine struct {
// contains filtered or unexported fields
}
UniqByLine filters reports to keep only one report by line of code.
func NewUniqByLine ¶
func NewUniqByLine(enable bool) *UniqByLine
func (*UniqByLine) Finish ¶
func (*UniqByLine) Finish()
func (*UniqByLine) Name ¶
func (*UniqByLine) Name() string
Source Files
¶
- base_rule.go
- cgo.go
- diff.go
- exclusion_generated_file_filter.go
- exclusion_generated_file_matcher.go
- exclusion_paths.go
- exclusion_presets.go
- exclusion_rules.go
- filename_unadjuster.go
- fixer.go
- invalid_issue.go
- issues.go
- max_from_linter.go
- max_per_file_from_linter.go
- max_same_issues.go
- nolint_filter.go
- path_absoluter.go
- path_prettifier.go
- path_relativity.go
- path_shortener.go
- processor.go
- severity.go
- sort_results.go
- source_code.go
- uniq_by_line.go