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:
- PathNormalization - Cross-platform path consistency
- EnableFilter - Remove violations for disabled rules
- SeverityOverride - Apply config severity overrides
- PathExclusionFilter - Remove per-rule path exclusions
- InlineDirectiveFilter - Apply # tally ignore=... etc.
- Deduplication - Remove duplicate violations
- Sorting - Stable output ordering
- 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.
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 ¶
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 ¶
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.
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.
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.
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.
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.
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.
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.
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.
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.