violations

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeBlock

type CodeBlock struct {
	File      string
	StartLine int
	EndLine   int
	Content   string
	Hash      string
}

CodeBlock represents a block of code for duplication analysis

type CommentedCodeDetector

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

CommentedCodeDetector detects blocks of commented-out code

func NewCommentedCodeDetector

func NewCommentedCodeDetector(config *DetectorConfig) *CommentedCodeDetector

NewCommentedCodeDetector creates a new commented code detector

func (*CommentedCodeDetector) Description

func (d *CommentedCodeDetector) Description() string

Description returns a description of what this detector checks for

func (*CommentedCodeDetector) Detect

func (d *CommentedCodeDetector) Detect(fileInfo *models.FileInfo, astInfo interface{}) []*models.Violation

Detect analyzes the provided file information and returns violations

func (*CommentedCodeDetector) Name

func (d *CommentedCodeDetector) Name() string

Name returns the name of this detector

type Detector

type Detector interface {
	// Detect analyzes the provided file information and returns violations
	Detect(fileInfo *models.FileInfo, astInfo interface{}) []*models.Violation

	// Name returns the name of this detector
	Name() string

	// Description returns a description of what this detector checks for
	Description() string
}

Detector defines the interface for violation detection

type DetectorConfig

type DetectorConfig struct {
	// Function thresholds
	MaxFunctionLines        int
	MaxCyclomaticComplexity int
	MaxParameters           int
	MaxNestingDepth         int

	// Code structure thresholds
	MaxClassLines int
	MaxMethods    int

	// Naming convention rules
	AllowSingleLetterVars    bool
	RequireCamelCase         bool
	RequireCommentsForPublic bool

	// Severity classification config
	SeverityConfig *SeverityConfig
}

DetectorConfig provides configuration for violation detection

func DefaultDetectorConfig

func DefaultDetectorConfig() *DetectorConfig

DefaultDetectorConfig returns the default configuration

func (*DetectorConfig) ClassifyViolationSeverity

func (c *DetectorConfig) ClassifyViolationSeverity(violationType models.ViolationType, actualValue, threshold int, context *ViolationContext) models.Severity

ClassifyViolationSeverity provides a convenience method for consistent severity classification

func (*DetectorConfig) ClassifyViolationSeverityFloat

func (c *DetectorConfig) ClassifyViolationSeverityFloat(violationType models.ViolationType, actualValue, threshold float64, context *ViolationContext) models.Severity

ClassifyViolationSeverityFloat provides severity classification for floating-point values

func (*DetectorConfig) GetSeverityClassifier

func (c *DetectorConfig) GetSeverityClassifier() *SeverityClassifier

GetSeverityClassifier returns a severity classifier instance for the detector config

type DetectorRegistry

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

DetectorRegistry manages all available detectors

func NewDetectorRegistry

func NewDetectorRegistry() *DetectorRegistry

NewDetectorRegistry creates a new detector registry

func (*DetectorRegistry) DetectAll

func (r *DetectorRegistry) DetectAll(fileInfo *models.FileInfo, astInfo interface{}) []*models.Violation

DetectAll runs all detectors against the provided file information

func (*DetectorRegistry) GetDetectors

func (r *DetectorRegistry) GetDetectors() []Detector

GetDetectors returns all registered detectors

func (*DetectorRegistry) RegisterDetector

func (r *DetectorRegistry) RegisterDetector(detector Detector)

RegisterDetector adds a detector to the registry

type DocumentationDetector

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

DocumentationDetector checks for missing or poor quality documentation

func NewDocumentationDetector

func NewDocumentationDetector(config *DetectorConfig) *DocumentationDetector

NewDocumentationDetector creates a new documentation detector

func (*DocumentationDetector) Description

func (d *DocumentationDetector) Description() string

Description returns a description of what this detector checks for

func (*DocumentationDetector) Detect

func (d *DocumentationDetector) Detect(fileInfo *models.FileInfo, astInfo interface{}) []*models.Violation

Detect analyzes the provided file information and returns violations

func (*DocumentationDetector) Name

func (d *DocumentationDetector) Name() string

Name returns the name of this detector

type DuplicationDetector

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

DuplicationDetector detects code duplication across files

func NewDuplicationDetector

func NewDuplicationDetector(config *DetectorConfig) *DuplicationDetector

NewDuplicationDetector creates a new duplication detector

func (*DuplicationDetector) Description

func (d *DuplicationDetector) Description() string

Description returns a description of what this detector checks for

func (*DuplicationDetector) Detect

func (d *DuplicationDetector) Detect(fileInfo *models.FileInfo, astInfo interface{}) []*models.Violation

Detect analyzes the provided file information and returns violations

func (*DuplicationDetector) Name

func (d *DuplicationDetector) Name() string

Name returns the name of this detector

func (*DuplicationDetector) Reset

func (d *DuplicationDetector) Reset()

Reset clears the hash cache (useful when starting a new scan)

type FunctionDetector

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

FunctionDetector detects function-related violations

func NewFunctionDetector

func NewFunctionDetector(config *DetectorConfig) *FunctionDetector

NewFunctionDetector creates a new function violation detector

func (*FunctionDetector) Description

func (d *FunctionDetector) Description() string

Description returns a description of what this detector checks for

func (*FunctionDetector) Detect

func (d *FunctionDetector) Detect(fileInfo *models.FileInfo, astInfo interface{}) []*models.Violation

Detect analyzes functions and returns violations

func (*FunctionDetector) Name

func (d *FunctionDetector) Name() string

Name returns the name of this detector

type MagicNumberDetector

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

MagicNumberDetector detects hardcoded magic numbers in code

func NewMagicNumberDetector

func NewMagicNumberDetector(config *DetectorConfig) *MagicNumberDetector

NewMagicNumberDetector creates a new magic number detector

func (*MagicNumberDetector) Description

func (d *MagicNumberDetector) Description() string

Description returns a description of what this detector checks for

func (*MagicNumberDetector) Detect

func (d *MagicNumberDetector) Detect(fileInfo *models.FileInfo, astInfo interface{}) []*models.Violation

Detect analyzes the provided file information and returns violations

func (*MagicNumberDetector) Name

func (d *MagicNumberDetector) Name() string

Name returns the name of this detector

type NamingDetector

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

NamingDetector detects naming convention violations

func NewNamingDetector

func NewNamingDetector(config *DetectorConfig) *NamingDetector

NewNamingDetector creates a new naming convention detector

func (*NamingDetector) Description

func (d *NamingDetector) Description() string

Description returns a description of what this detector checks for

func (*NamingDetector) Detect

func (d *NamingDetector) Detect(fileInfo *models.FileInfo, astInfo interface{}) []*models.Violation

Detect analyzes naming conventions and returns violations

func (*NamingDetector) Name

func (d *NamingDetector) Name() string

Name returns the name of this detector

type SeverityClassifier

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

SeverityClassifier provides centralized severity classification logic

func NewSeverityClassifier

func NewSeverityClassifier(config *SeverityConfig) *SeverityClassifier

NewSeverityClassifier creates a new severity classifier

func (*SeverityClassifier) ClassifySeverity

func (s *SeverityClassifier) ClassifySeverity(violationType models.ViolationType, actualValue, threshold int, context *ViolationContext) models.Severity

ClassifySeverity calculates the severity level based on violation metrics and context

func (*SeverityClassifier) ClassifySeverityFloat

func (s *SeverityClassifier) ClassifySeverityFloat(violationType models.ViolationType, actualValue, threshold float64, context *ViolationContext) models.Severity

ClassifySeverityFloat calculates severity for floating-point values

func (*SeverityClassifier) GetSeverityDescription

func (s *SeverityClassifier) GetSeverityDescription(severity models.Severity) string

GetSeverityDescription returns a human-readable description of the severity level

func (*SeverityClassifier) GetSeverityWeight

func (s *SeverityClassifier) GetSeverityWeight(severity models.Severity) int

GetSeverityWeight returns the numeric weight for sorting and prioritization

func (*SeverityClassifier) GetThresholdMultiplier

func (s *SeverityClassifier) GetThresholdMultiplier(severity models.Severity) float64

GetThresholdMultiplier returns the configured multiplier for a severity level

func (*SeverityClassifier) IsContextBasedAdjustmentEnabled

func (s *SeverityClassifier) IsContextBasedAdjustmentEnabled() bool

IsContextBasedAdjustmentEnabled checks if context-based adjustments are enabled

type SeverityConfig

type SeverityConfig struct {
	// Multipliers for different severity levels
	LowThresholdMultiplier      float64 `yaml:"low_threshold_multiplier"`      // Default: 1.0 (at threshold)
	MediumThresholdMultiplier   float64 `yaml:"medium_threshold_multiplier"`   // Default: 1.5
	HighThresholdMultiplier     float64 `yaml:"high_threshold_multiplier"`     // Default: 2.0
	CriticalThresholdMultiplier float64 `yaml:"critical_threshold_multiplier"` // Default: 3.0

	// Context-based severity adjustments
	PublicFunctionSeverityBoost bool `yaml:"public_function_severity_boost"` // Boost severity for public functions
	TestFilesSeverityReduction  bool `yaml:"test_files_severity_reduction"`  // Reduce severity for test files
	LegacyCodeSeverityReduction bool `yaml:"legacy_code_severity_reduction"` // Reduce severity for legacy code

	// Violation type specific severity overrides
	ViolationTypeWeights map[models.ViolationType]float64 `yaml:"violation_type_weights"`
}

SeverityConfig defines thresholds for severity classification

func DefaultSeverityConfig

func DefaultSeverityConfig() *SeverityConfig

DefaultSeverityConfig returns the default severity configuration

type StructureDetector

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

StructureDetector detects code structure-related violations

func NewStructureDetector

func NewStructureDetector(config *DetectorConfig) *StructureDetector

NewStructureDetector creates a new structure violation detector

func (*StructureDetector) Description

func (d *StructureDetector) Description() string

Description returns a description of what this detector checks for

func (*StructureDetector) Detect

func (d *StructureDetector) Detect(fileInfo *models.FileInfo, astInfo interface{}) []*models.Violation

Detect analyzes code structure and returns violations

func (*StructureDetector) Name

func (d *StructureDetector) Name() string

Name returns the name of this detector

type TodoTrackerDetector

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

TodoTrackerDetector tracks TODO, FIXME, and other technical debt markers

func NewTodoTrackerDetector

func NewTodoTrackerDetector(config *DetectorConfig) *TodoTrackerDetector

NewTodoTrackerDetector creates a new TODO/FIXME tracker detector

func (*TodoTrackerDetector) Description

func (d *TodoTrackerDetector) Description() string

Description returns a description of what this detector checks for

func (*TodoTrackerDetector) Detect

func (d *TodoTrackerDetector) Detect(fileInfo *models.FileInfo, astInfo interface{}) []*models.Violation

Detect analyzes the provided file information and returns violations

func (*TodoTrackerDetector) Name

func (d *TodoTrackerDetector) Name() string

Name returns the name of this detector

type ViolationContext

type ViolationContext struct {
	IsPublic       bool   `json:"is_public"`
	IsTestFile     bool   `json:"is_test_file"`
	IsLegacyCode   bool   `json:"is_legacy_code"`
	FileExtension  string `json:"file_extension"`
	PackageName    string `json:"package_name"`
	FunctionName   string `json:"function_name,omitempty"`
	TypeName       string `json:"type_name,omitempty"`
	ProjectContext string `json:"project_context,omitempty"`
}

ViolationContext provides context information for severity calculation

Jump to

Keyboard shortcuts

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