processor

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package processor provides a composable violation processing pipeline.

The processor chain pattern is inspired by golangci-lint's approach: violations flow through a sequence of processors, each transforming the slice (filtering, modifying, or augmenting).

Standard pipeline order:

  1. PathNormalization - Cross-platform path consistency
  2. EnableFilter - Remove violations for disabled rules
  3. SeverityOverride - Apply config severity overrides
  4. PathExclusionFilter - Remove per-rule path exclusions
  5. InlineDirectiveFilter - Apply # tally ignore=... etc.
  6. Deduplication - Remove duplicate violations
  7. Sorting - Stable output ordering
  8. SnippetAttachment - Populate SourceCode field

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

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

Chain runs processors in sequence.

func NewChain

func NewChain(processors ...Processor) *Chain

NewChain creates a new processor chain.

func (*Chain) Process

func (c *Chain) Process(violations []rules.Violation, ctx *Context) []rules.Violation

Process runs all processors in sequence.

type Context

type Context struct {
	// FileConfigs maps file paths to their loaded configuration.
	// Each file may have a different config due to cascading discovery.
	FileConfigs map[string]*config.Config

	// DefaultConfig is the fallback config when a file-specific config is not found.
	// This is typically the first file's config (for output settings).
	DefaultConfig *config.Config

	// FileSources maps file paths to their raw source content.
	// Used by SnippetAttachment for extracting source code.
	FileSources map[string][]byte
	// contains filtered or unexported fields
}

Context provides shared state for processors. Populated once before running the chain, then passed to each processor.

NOTE: Context is not safe for concurrent access. The processor chain runs sequentially, so no synchronization is needed.

func NewContext

func NewContext(
	fileConfigs map[string]*config.Config,
	defaultCfg *config.Config,
	fileSources map[string][]byte,
) *Context

NewContext creates a new processor context. fileConfigs maps each file path to its specific config. defaultCfg is used for output settings and as fallback.

func (*Context) ConfigForFile

func (ctx *Context) ConfigForFile(file string) *config.Config

ConfigForFile returns the config for a specific file. Falls back to DefaultConfig if no file-specific config exists. Handles cross-platform path lookups by trying both forward and backslash variants.

func (*Context) GetSourceMap

func (ctx *Context) GetSourceMap(file string) *sourcemap.SourceMap

GetSourceMap returns or creates a SourceMap for the given file. Returns nil if the file is not in FileSources. Handles cross-platform path lookups by trying both forward and backslash variants.

NOTE: This method is not safe for concurrent calls. See Context docs.

type Deduplication

type Deduplication struct{}

Deduplication removes duplicate violations. Two violations are considered duplicates if they have the same file, line, and rule code. This handles cases where multiple rules report the same issue or the same rule reports the same issue multiple times.

func NewDeduplication

func NewDeduplication() *Deduplication

NewDeduplication creates a new deduplication processor.

func (*Deduplication) Name

func (p *Deduplication) Name() string

Name returns the processor's identifier.

func (*Deduplication) Process

func (p *Deduplication) Process(violations []rules.Violation, _ *Context) []rules.Violation

Process removes duplicate violations. Keeps the first occurrence of each unique (file, line, rule) combination.

type EnableFilter

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

EnableFilter removes violations for disabled rules. Filters out violations with severity="off". Also respects Include/Exclude patterns from config.

func NewEnableFilter

func NewEnableFilter() *EnableFilter

NewEnableFilter creates a new enable filter processor. Uses the default registry. For testing, use NewEnableFilterWithRegistry.

func NewEnableFilterWithRegistry

func NewEnableFilterWithRegistry(registry *rules.Registry) *EnableFilter

NewEnableFilterWithRegistry creates an enable filter with a custom registry.

func (*EnableFilter) Name

func (p *EnableFilter) Name() string

Name returns the processor's identifier.

func (*EnableFilter) Process

func (p *EnableFilter) Process(violations []rules.Violation, ctx *Context) []rules.Violation

Process filters out violations for disabled rules. Rules are disabled if:

  1. Severity is "off" (after SeverityOverride has run)
  2. Excluded by Include/Exclude patterns

type InlineDirectiveFilter

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

InlineDirectiveFilter applies inline ignore directives. Supports # tally ignore=..., # hadolint ignore=..., and # check=skip=...

This processor collects additional violations for:

  • Parse errors in directives
  • Unused directives (if WarnUnused is enabled)
  • Missing reason= (if RequireReason is enabled)

NOTE: This processor is stateful - it stores additional violations that must be retrieved via AdditionalViolations() after Process() completes. The state is reset on each Process() call, making it safe for sequential reuse but not for concurrent or multi-pass processing.

func NewInlineDirectiveFilter

func NewInlineDirectiveFilter() *InlineDirectiveFilter

NewInlineDirectiveFilter creates a new inline directive filter processor. Uses the default registry. For testing, use NewInlineDirectiveFilterWithRegistry.

func NewInlineDirectiveFilterWithRegistry

func NewInlineDirectiveFilterWithRegistry(registry *rules.Registry) *InlineDirectiveFilter

NewInlineDirectiveFilterWithRegistry creates an inline directive filter with a custom registry.

func (*InlineDirectiveFilter) AdditionalViolations

func (p *InlineDirectiveFilter) AdditionalViolations() []rules.Violation

AdditionalViolations returns violations generated by the directive processor. These include parse errors, unused directives, and missing reasons. Call this after Process() to get all directive-related warnings. Returns a defensive copy to prevent external mutation of internal state.

func (*InlineDirectiveFilter) Name

func (p *InlineDirectiveFilter) Name() string

Name returns the processor's identifier.

func (*InlineDirectiveFilter) Process

func (p *InlineDirectiveFilter) Process(
	violations []rules.Violation,
	ctx *Context,
) []rules.Violation

Process applies inline directives to filter violations. Also collects additional violations for invalid/unused directives.

type PathExclusionFilter

type PathExclusionFilter struct{}

PathExclusionFilter removes violations based on per-rule path exclusions. Uses config.Rules.GetExcludePaths() to get exclusion patterns for each rule.

func NewPathExclusionFilter

func NewPathExclusionFilter() *PathExclusionFilter

NewPathExclusionFilter creates a new path exclusion filter processor.

func (*PathExclusionFilter) Name

func (p *PathExclusionFilter) Name() string

Name returns the processor's identifier.

func (*PathExclusionFilter) Process

func (p *PathExclusionFilter) Process(violations []rules.Violation, ctx *Context) []rules.Violation

Process filters out violations for files that match exclusion patterns.

type PathNormalization

type PathNormalization struct{}

PathNormalization converts file paths to forward slashes for cross-platform consistency. This ensures output is identical regardless of OS (Windows vs Unix).

func NewPathNormalization

func NewPathNormalization() *PathNormalization

NewPathNormalization creates a new path normalization processor.

func (*PathNormalization) Name

func (p *PathNormalization) Name() string

Name returns the processor's identifier.

func (*PathNormalization) Process

func (p *PathNormalization) Process(violations []rules.Violation, _ *Context) []rules.Violation

Process normalizes all file paths to use forward slashes.

type Processor

type Processor interface {
	// Name returns the processor's identifier (for debugging/logging).
	Name() string

	// Process applies the processor's logic to violations.
	// Returns the transformed slice (may be same, filtered, or modified).
	// Must not modify the input slice; return a new slice if filtering.
	Process(violations []rules.Violation, ctx *Context) []rules.Violation
}

Processor transforms a slice of violations. Implementations should be stateless where possible, using Context for shared state.

type SeverityOverride

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

SeverityOverride applies severity overrides from configuration. Allows users to downgrade warnings to info, upgrade info to errors, etc. Also auto-enables rules with DefaultSeverity="off" when config is provided.

func NewSeverityOverride

func NewSeverityOverride() *SeverityOverride

NewSeverityOverride creates a new severity override processor.

func NewSeverityOverrideWithRegistry

func NewSeverityOverrideWithRegistry(registry *rules.Registry) *SeverityOverride

NewSeverityOverrideWithRegistry creates a severity override processor with a custom registry.

func (*SeverityOverride) Name

func (p *SeverityOverride) Name() string

Name returns the processor's identifier.

func (*SeverityOverride) Process

func (p *SeverityOverride) Process(violations []rules.Violation, ctx *Context) []rules.Violation

Process applies severity overrides from config. Also auto-enables rules with DefaultSeverity="off" when config is provided.

type SnippetAttachment

type SnippetAttachment struct{}

SnippetAttachment populates the SourceCode field of violations. This extracts the relevant source code snippet for each violation location, enabling reporters to display context without re-parsing files.

func NewSnippetAttachment

func NewSnippetAttachment() *SnippetAttachment

NewSnippetAttachment creates a new snippet attachment processor.

func (*SnippetAttachment) Name

func (p *SnippetAttachment) Name() string

Name returns the processor's identifier.

func (*SnippetAttachment) Process

func (p *SnippetAttachment) Process(violations []rules.Violation, ctx *Context) []rules.Violation

Process attaches source code snippets to violations. Skips violations that already have SourceCode set or where the file is not in the context's FileSources.

type Sorting

type Sorting struct{}

Sorting ensures stable, deterministic output ordering. Order: file path, then line number, then column, then rule code. This ensures identical output across runs and platforms.

func NewSorting

func NewSorting() *Sorting

NewSorting creates a new sorting processor.

func (*Sorting) Name

func (p *Sorting) Name() string

Name returns the processor's identifier.

func (*Sorting) Process

func (p *Sorting) Process(violations []rules.Violation, _ *Context) []rules.Violation

Process sorts violations in a stable order. Uses the existing reporter.SortViolations implementation.

type Supersession

type Supersession struct{}

Supersession suppresses lower-severity violations when an error-level violation exists at the same location (file + line). This handles cross-rule interactions where a cosmetic suggestion (e.g. StageNameCasing) is meaningless when an error (e.g. ReservedStageName) already flags the line.

func NewSupersession

func NewSupersession() *Supersession

NewSupersession creates a new supersession processor.

func (*Supersession) Name

func (p *Supersession) Name() string

Name returns the processor's identifier.

func (*Supersession) Process

func (p *Supersession) Process(violations []rules.Violation, _ *Context) []rules.Violation

Process removes violations that are superseded by a higher-severity violation at the same file+line. Only error-level violations suppress lower-severity ones.

Jump to

Keyboard shortcuts

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