processors

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2025 License: GPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

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

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

func (*ExclusionPaths) Process

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

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

func (*ExclusionRules) Process

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

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

func (*FilenameUnadjuster) Process

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

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.

func NewFixer

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

func (Fixer) Finish

func (Fixer) Finish()

func (Fixer) Name

func (Fixer) Name() string

func (Fixer) Process

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

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

func (*GeneratedFileFilter) Process

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

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

func (InvalidIssue) Process

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

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

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

func NewNolintFilter

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

func (*NolintFilter) Finish

func (p *NolintFilter) Finish()

func (*NolintFilter) Name

func (*NolintFilter) Name() string

func (*NolintFilter) Process

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

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

func (*PathAbsoluter) Process

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, cfg *config.Output) *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

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

func (*PathRelativity) Process

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

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

func (PathShortener) Process

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

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

func NewSeverity(log logutils.Log, lines *fsutils.LineCache, cfg *config.Severity) *Severity

func (*Severity) Finish

func (*Severity) Finish()

func (*Severity) Name

func (p *Severity) Name() string

func (*Severity) Process

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

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

func (SortResults) Process

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

Process is performing sorting of the result issues.

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

func (SourceCode) Process

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