processors

package
v1.64.5 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: GPL-3.0 Imports: 36 Imported by: 14

Documentation

Index

Constants

View Source
const (
	AutogeneratedModeLax     = "lax"
	AutogeneratedModeStrict  = "strict"
	AutogeneratedModeDisable = "disable"
)

Variables

View Source
var StdExcludeDirRegexps = []string{
	normalizePathRegex("vendor"),
	normalizePathRegex("third_party"),
	normalizePathRegex("testdata"),
	normalizePathRegex("examples"),
	normalizePathRegex("Godeps"),
	normalizePathRegex("builtin"),
}

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.

func NewCgo

func NewCgo(env *goutil.Env) *Cgo

func (*Cgo) Finish

func (*Cgo) Finish()

func (*Cgo) Name

func (*Cgo) Name() string

func (*Cgo) Process

func (p *Cgo) Process(issues []result.Issue) ([]result.Issue, error)

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.

func NewDiff

func NewDiff(cfg *config.Issues) *Diff

func (*Diff) Finish

func (*Diff) Finish()

func (*Diff) Name

func (*Diff) Name() string

func (*Diff) Process

func (p *Diff) Process(issues []result.Issue) ([]result.Issue, error)

type ExclusionPaths added in v1.64.0

type ExclusionPaths struct {
	// contains filtered or unexported fields
}

func NewExclusionPaths added in v1.64.0

func NewExclusionPaths(log logutils.Log, cfg *config.LinterExclusions) (*ExclusionPaths, error)

func (*ExclusionPaths) Finish added in v1.64.0

func (p *ExclusionPaths) Finish()

func (*ExclusionPaths) Name added in v1.64.0

func (*ExclusionPaths) Name() string

func (*ExclusionPaths) Process added in v1.64.0

func (p *ExclusionPaths) Process(issues []result.Issue) ([]result.Issue, error)

type ExclusionRules added in v1.64.0

type ExclusionRules struct {
	// contains filtered or unexported fields
}

func NewExclusionRules added in v1.64.0

func NewExclusionRules(log logutils.Log, files *fsutils.Files,
	cfg *config.LinterExclusions, oldCfg *config.Issues) *ExclusionRules

func (*ExclusionRules) Finish added in v1.64.0

func (p *ExclusionRules) Finish()

func (*ExclusionRules) Name added in v1.64.0

func (*ExclusionRules) Name() string

func (*ExclusionRules) Process added in v1.64.0

func (p *ExclusionRules) Process(issues []result.Issue) ([]result.Issue, error)

type FilenameUnadjuster added in v1.17.0

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 added in v1.17.0

func NewFilenameUnadjuster(pkgs []*packages.Package, log logutils.Log) *FilenameUnadjuster

func (*FilenameUnadjuster) Finish added in v1.17.0

func (*FilenameUnadjuster) Finish()

func (*FilenameUnadjuster) Name added in v1.17.0

func (*FilenameUnadjuster) Name() string

func (*FilenameUnadjuster) Process added in v1.17.0

func (p *FilenameUnadjuster) Process(issues []result.Issue) ([]result.Issue, error)

type Fixer added in v1.15.0

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.

func NewFixer added in v1.15.0

func NewFixer(cfg *config.Config, log logutils.Log, fileCache *fsutils.FileCache, formatter *goformatters.MetaFormatter) *Fixer

func (Fixer) Finish added in v1.52.1

func (Fixer) Finish()

func (Fixer) Name added in v1.52.1

func (Fixer) Name() string

func (Fixer) Process added in v1.15.0

func (p Fixer) Process(issues []result.Issue) ([]result.Issue, error)

type GeneratedFileFilter added in v1.64.0

type GeneratedFileFilter struct {
	// contains filtered or unexported fields
}

GeneratedFileFilter filters generated files.

  • mode "lax": see `isGeneratedFileLax` documentation.
  • mode "strict": see `isGeneratedFileStrict` documentation.
  • mode "disable": skips this processor.

func NewGeneratedFileFilter added in v1.64.0

func NewGeneratedFileFilter(mode string) *GeneratedFileFilter

func (*GeneratedFileFilter) Finish added in v1.64.0

func (*GeneratedFileFilter) Finish()

func (*GeneratedFileFilter) Name added in v1.64.0

func (*GeneratedFileFilter) Name() string

func (*GeneratedFileFilter) Process added in v1.64.0

func (p *GeneratedFileFilter) Process(issues []result.Issue) ([]result.Issue, error)

type IdentifierMarker added in v1.15.0

type IdentifierMarker struct {
	// contains filtered or unexported fields
}

IdentifierMarker modifies report text. It must be before [Exclude] and [ExcludeRules]: users configure exclusions based on the modified text.

func NewIdentifierMarker added in v1.15.0

func NewIdentifierMarker() *IdentifierMarker

func (*IdentifierMarker) Finish added in v1.15.0

func (*IdentifierMarker) Finish()

func (*IdentifierMarker) Name added in v1.15.0

func (*IdentifierMarker) Name() string

func (*IdentifierMarker) Process added in v1.15.0

func (p *IdentifierMarker) Process(issues []result.Issue) ([]result.Issue, error)

type InvalidIssue added in v1.57.1

type InvalidIssue struct {
	// contains filtered or unexported fields
}

InvalidIssue filters invalid reports.

  • non-go files (except `go.mod`)
  • reports without file path

func NewInvalidIssue added in v1.57.1

func NewInvalidIssue(log logutils.Log) *InvalidIssue

func (InvalidIssue) Finish added in v1.57.1

func (InvalidIssue) Finish()

func (InvalidIssue) Name added in v1.57.1

func (InvalidIssue) Name() string

func (InvalidIssue) Process added in v1.57.1

func (p InvalidIssue) Process(issues []result.Issue) ([]result.Issue, error)

type MaxFromLinter

type MaxFromLinter struct {
	// contains filtered or unexported fields
}

MaxFromLinter limits the number of reports from the same linter.

func NewMaxFromLinter

func NewMaxFromLinter(limit int, log logutils.Log, cfg *config.Config) *MaxFromLinter

func (*MaxFromLinter) Finish

func (p *MaxFromLinter) Finish()

func (*MaxFromLinter) Name

func (*MaxFromLinter) Name() string

func (*MaxFromLinter) Process

func (p *MaxFromLinter) Process(issues []result.Issue) ([]result.Issue, error)

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

func (*MaxPerFileFromLinter) Process

func (p *MaxPerFileFromLinter) Process(issues []result.Issue) ([]result.Issue, error)

type MaxSameIssues

type MaxSameIssues struct {
	// contains filtered or unexported fields
}

MaxSameIssues limits the number of reports with the same text.

func NewMaxSameIssues

func NewMaxSameIssues(limit int, log logutils.Log, cfg *config.Config) *MaxSameIssues

func (*MaxSameIssues) Finish

func (p *MaxSameIssues) Finish()

func (*MaxSameIssues) Name

func (*MaxSameIssues) Name() string

func (*MaxSameIssues) Process

func (p *MaxSameIssues) Process(issues []result.Issue) ([]result.Issue, error)

type NolintFilter added in v1.64.0

type NolintFilter struct {
	// contains filtered or unexported fields
}

NolintFilter filters and sorts reports related to `nolint` directives.

func NewNolintFilter added in v1.64.0

func NewNolintFilter(log logutils.Log, dbManager *lintersdb.Manager, enabledLinters map[string]*linter.Config) *NolintFilter

func (*NolintFilter) Finish added in v1.64.0

func (p *NolintFilter) Finish()

func (*NolintFilter) Name added in v1.64.0

func (*NolintFilter) Name() string

func (*NolintFilter) Process added in v1.64.0

func (p *NolintFilter) Process(issues []result.Issue) ([]result.Issue, error)

type PathAbsoluter added in v1.64.0

type PathAbsoluter struct {
	// contains filtered or unexported fields
}

PathAbsoluter ensures that representation of path are absolute.

func NewPathAbsoluter added in v1.64.0

func NewPathAbsoluter(log logutils.Log) *PathAbsoluter

func (*PathAbsoluter) Finish added in v1.64.0

func (*PathAbsoluter) Finish()

func (*PathAbsoluter) Name added in v1.64.0

func (*PathAbsoluter) Name() string

func (*PathAbsoluter) Process added in v1.64.0

func (p *PathAbsoluter) Process(issues []result.Issue) ([]result.Issue, error)

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, prefix string) *PathPrettifier

func (*PathPrettifier) Finish

func (*PathPrettifier) Finish()

func (*PathPrettifier) Name

func (*PathPrettifier) Name() string

func (*PathPrettifier) Process

func (p *PathPrettifier) Process(issues []result.Issue) ([]result.Issue, error)

type PathRelativity added in v1.64.0

type PathRelativity struct {
	// contains filtered or unexported fields
}

PathRelativity computes result.Issue.RelativePath and result.Issue.WorkingDirectoryRelativePath, based on the base path.

func NewPathRelativity added in v1.64.0

func NewPathRelativity(log logutils.Log, basePath string) (*PathRelativity, error)

func (*PathRelativity) Finish added in v1.64.0

func (*PathRelativity) Finish()

func (*PathRelativity) Name added in v1.64.0

func (*PathRelativity) Name() string

func (*PathRelativity) Process added in v1.64.0

func (p *PathRelativity) Process(issues []result.Issue) ([]result.Issue, error)

type PathShortener added in v1.11.1

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 added in v1.11.1

func NewPathShortener() *PathShortener

func (PathShortener) Finish added in v1.11.1

func (PathShortener) Finish()

func (PathShortener) Name added in v1.11.1

func (PathShortener) Name() string

func (PathShortener) Process added in v1.11.1

func (p PathShortener) Process(issues []result.Issue) ([]result.Issue, error)

type Processor

type Processor interface {
	Process(issues []result.Issue) ([]result.Issue, error)
	Name() string
	Finish()
}

type Severity added in v1.57.0

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 added in v1.57.0

func NewSeverity(log logutils.Log, files *fsutils.Files, cfg *config.Severity) *Severity

func (*Severity) Finish added in v1.57.0

func (*Severity) Finish()

func (*Severity) Name added in v1.57.0

func (p *Severity) Name() string

func (*Severity) Process added in v1.57.0

func (p *Severity) Process(issues []result.Issue) ([]result.Issue, error)

type SkipDirs added in v1.11.1

type SkipDirs struct {
	// contains filtered or unexported fields
}

SkipDirs filters reports based on directory names. It uses the shortest relative paths and `path-prefix` option. TODO(ldez): should be removed in v2.

func NewSkipDirs added in v1.11.1

func NewSkipDirs(log logutils.Log, patterns, args []string, pathPrefix string) (*SkipDirs, error)

func (*SkipDirs) Finish added in v1.11.1

func (p *SkipDirs) Finish()

func (*SkipDirs) Name added in v1.11.1

func (*SkipDirs) Name() string

func (*SkipDirs) Process added in v1.11.1

func (p *SkipDirs) Process(issues []result.Issue) ([]result.Issue, error)

type SkipFiles added in v1.6.1

type SkipFiles struct {
	// contains filtered or unexported fields
}

SkipFiles filters reports based on filename.

It uses the shortest relative paths and `path-prefix` option. TODO(ldez): should be removed in v2.

func NewSkipFiles added in v1.6.1

func NewSkipFiles(patterns []string, pathPrefix string) (*SkipFiles, error)

func (*SkipFiles) Finish added in v1.6.1

func (*SkipFiles) Finish()

func (*SkipFiles) Name added in v1.6.1

func (*SkipFiles) Name() string

func (*SkipFiles) Process added in v1.6.1

func (p *SkipFiles) Process(issues []result.Issue) ([]result.Issue, error)

type SortResults added in v1.29.0

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 added in v1.29.0

func NewSortResults(cfg *config.Output) *SortResults

func (SortResults) Finish added in v1.29.0

func (SortResults) Finish()

func (SortResults) Name added in v1.29.0

func (SortResults) Name() string

func (SortResults) Process added in v1.29.0

func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error)

Process is performing sorting of the result issues.

type SourceCode added in v1.10.1

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 added in v1.10.1

func NewSourceCode(lc *fsutils.LineCache, log logutils.Log) *SourceCode

func (SourceCode) Finish added in v1.10.1

func (SourceCode) Finish()

func (SourceCode) Name added in v1.10.1

func (SourceCode) Name() string

func (SourceCode) Process added in v1.10.1

func (p SourceCode) Process(issues []result.Issue) ([]result.Issue, error)

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

func (*UniqByLine) Process

func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error)

Jump to

Keyboard shortcuts

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