analyzer

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEachFile

func ForEachFile[T any](files []string, fn func(string) (T, error)) []T

ForEachFile processes files in parallel, calling fn for each file. No parser is provided; use this for non-AST operations (e.g., SATD scanning). Uses 2x NumCPU workers by default.

func ForEachFileWithProgress

func ForEachFileWithProgress[T any](files []string, fn func(string) (T, error), onProgress ProgressFunc) []T

ForEachFileWithProgress processes files in parallel with optional progress callback.

func MapFiles

func MapFiles[T any](files []string, fn func(*parser.Parser, string) (T, error)) []T

MapFiles processes files in parallel, calling fn for each file with a dedicated parser. Results are collected and returned in arbitrary order. Errors from individual files are silently skipped. Uses 2x NumCPU workers by default (optimal for mixed I/O and CGO workloads).

func MapFilesN

func MapFilesN[T any](files []string, maxWorkers int, fn func(*parser.Parser, string) (T, error), onProgress ProgressFunc) []T

MapFilesN processes files with a configurable worker count. If maxWorkers is <= 0, defaults to 2x NumCPU.

func MapFilesWithProgress

func MapFilesWithProgress[T any](files []string, fn func(*parser.Parser, string) (T, error), onProgress ProgressFunc) []T

MapFilesWithProgress processes files in parallel with optional progress callback.

Types

type AstContext added in v1.2.0

type AstContext struct {
	NodeType              AstNodeType
	ParentFunction        string
	Complexity            uint32
	SiblingsCount         int
	NestingDepth          int
	SurroundingStatements []string
}

AstContext provides context about a code location for severity adjustment. Matches PMAT's AstContext struct.

type AstNodeType added in v1.2.0

type AstNodeType int

AstNodeType represents the type of AST context for a code location. Matches PMAT's AstNodeType enum for severity adjustment.

const (
	// AstNodeRegular is a normal code location with no special context.
	AstNodeRegular AstNodeType = iota
	// AstNodeSecurityFunction is code within a security-related function.
	AstNodeSecurityFunction
	// AstNodeDataValidation is code within a data validation function.
	AstNodeDataValidation
	// AstNodeTestFunction is code within a test function.
	AstNodeTestFunction
	// AstNodeMockImplementation is code within a mock/stub implementation.
	AstNodeMockImplementation
)

type ChurnAnalyzer

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

ChurnAnalyzer analyzes git commit history for file churn.

func NewChurnAnalyzer

func NewChurnAnalyzer(days int) *ChurnAnalyzer

NewChurnAnalyzer creates a new churn analyzer.

func (*ChurnAnalyzer) AnalyzeFiles

func (a *ChurnAnalyzer) AnalyzeFiles(repoPath string, files []string) (*models.ChurnAnalysis, error)

AnalyzeFiles analyzes churn for specific files.

func (*ChurnAnalyzer) AnalyzeRepo

func (a *ChurnAnalyzer) AnalyzeRepo(repoPath string) (*models.ChurnAnalysis, error)

AnalyzeRepo analyzes git history for a repository.

func (*ChurnAnalyzer) SetSpinner

func (a *ChurnAnalyzer) SetSpinner(spinner *progress.Tracker)

SetSpinner sets a spinner for progress indication during analysis.

type ComplexityAnalyzer

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

ComplexityAnalyzer computes cyclomatic and cognitive complexity.

func NewComplexityAnalyzer

func NewComplexityAnalyzer() *ComplexityAnalyzer

NewComplexityAnalyzer creates a new complexity analyzer.

func NewComplexityAnalyzerWithOptions added in v1.2.0

func NewComplexityAnalyzerWithOptions(opts ComplexityOptions) *ComplexityAnalyzer

NewComplexityAnalyzerWithOptions creates a new complexity analyzer with options.

func (*ComplexityAnalyzer) AnalyzeFile

func (a *ComplexityAnalyzer) AnalyzeFile(path string) (*models.FileComplexity, error)

AnalyzeFile analyzes complexity for a single file.

func (*ComplexityAnalyzer) AnalyzeProject

func (a *ComplexityAnalyzer) AnalyzeProject(files []string) (*models.ComplexityAnalysis, error)

AnalyzeProject analyzes all files in a project using parallel processing.

func (*ComplexityAnalyzer) AnalyzeProjectWithProgress

func (a *ComplexityAnalyzer) AnalyzeProjectWithProgress(files []string, onProgress ProgressFunc) (*models.ComplexityAnalysis, error)

AnalyzeProjectWithProgress analyzes all files with optional progress callback.

func (*ComplexityAnalyzer) Close

func (a *ComplexityAnalyzer) Close()

Close releases analyzer resources.

type ComplexityOptions added in v1.2.0

type ComplexityOptions struct {
	IncludeHalstead bool // Calculate Halstead software science metrics
}

ComplexityOptions configures complexity analysis behavior.

func DefaultComplexityOptions added in v1.2.0

func DefaultComplexityOptions() ComplexityOptions

DefaultComplexityOptions returns default complexity analysis options.

type DeadCodeAnalyzer

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

DeadCodeAnalyzer detects unused functions, variables, and unreachable code.

func NewDeadCodeAnalyzer

func NewDeadCodeAnalyzer(confidence float64) *DeadCodeAnalyzer

NewDeadCodeAnalyzer creates a new dead code analyzer.

func (*DeadCodeAnalyzer) AnalyzeFile

func (a *DeadCodeAnalyzer) AnalyzeFile(path string) (*fileDeadCode, error)

AnalyzeFile analyzes a single file for dead code.

func (*DeadCodeAnalyzer) AnalyzeProject

func (a *DeadCodeAnalyzer) AnalyzeProject(files []string) (*models.DeadCodeAnalysis, error)

AnalyzeProject analyzes dead code across a project using parallel processing.

func (*DeadCodeAnalyzer) AnalyzeProjectWithProgress

func (a *DeadCodeAnalyzer) AnalyzeProjectWithProgress(files []string, onProgress ProgressFunc) (*models.DeadCodeAnalysis, error)

AnalyzeProjectWithProgress analyzes dead code with optional progress callback.

func (*DeadCodeAnalyzer) Close

func (a *DeadCodeAnalyzer) Close()

Close releases analyzer resources.

type DefectAnalyzer

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

DefectAnalyzer predicts defect probability using PMAT weights.

func NewDefectAnalyzer

func NewDefectAnalyzer(churnDays int) *DefectAnalyzer

NewDefectAnalyzer creates a new defect analyzer with default PMAT weights.

func (*DefectAnalyzer) AnalyzeProject

func (a *DefectAnalyzer) AnalyzeProject(repoPath string, files []string) (*models.DefectAnalysis, error)

AnalyzeProject predicts defects across a project.

func (*DefectAnalyzer) Close

func (a *DefectAnalyzer) Close()

Close releases analyzer resources.

type DuplicateAnalyzer

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

DuplicateAnalyzer detects code clones using MinHash.

func NewDuplicateAnalyzer

func NewDuplicateAnalyzer(minLines int, threshold float64) *DuplicateAnalyzer

NewDuplicateAnalyzer creates a new duplicate analyzer.

func (*DuplicateAnalyzer) AnalyzeProject

func (a *DuplicateAnalyzer) AnalyzeProject(files []string) (*models.CloneAnalysis, error)

AnalyzeProject detects code clones across a project.

func (*DuplicateAnalyzer) AnalyzeProjectWithProgress

func (a *DuplicateAnalyzer) AnalyzeProjectWithProgress(files []string, onProgress ProgressFunc) (*models.CloneAnalysis, error)

AnalyzeProjectWithProgress detects code clones with optional progress callback.

func (*DuplicateAnalyzer) Close

func (a *DuplicateAnalyzer) Close()

Close releases analyzer resources.

type GraphAnalyzer

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

GraphAnalyzer builds dependency graphs from source code.

func NewGraphAnalyzer

func NewGraphAnalyzer(scope GraphScope) *GraphAnalyzer

NewGraphAnalyzer creates a new graph analyzer.

func (*GraphAnalyzer) AnalyzeProject

func (a *GraphAnalyzer) AnalyzeProject(files []string) (*models.DependencyGraph, error)

AnalyzeProject builds a dependency graph for a project.

func (*GraphAnalyzer) AnalyzeProjectWithProgress

func (a *GraphAnalyzer) AnalyzeProjectWithProgress(files []string, onProgress ProgressFunc) (*models.DependencyGraph, error)

AnalyzeProjectWithProgress builds a dependency graph with optional progress callback.

func (*GraphAnalyzer) CalculateMetrics

func (a *GraphAnalyzer) CalculateMetrics(graph *models.DependencyGraph) *models.GraphMetrics

CalculateMetrics computes graph metrics like PageRank.

func (*GraphAnalyzer) Close

func (a *GraphAnalyzer) Close()

Close releases analyzer resources.

type GraphScope

type GraphScope string

GraphScope determines the granularity of graph nodes.

const (
	ScopeFile     GraphScope = "file"
	ScopeFunction GraphScope = "function"
	ScopeModule   GraphScope = "module"
	ScopePackage  GraphScope = "package"
)

type HalsteadAnalyzer added in v1.2.0

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

HalsteadAnalyzer calculates Halstead software science metrics.

func NewHalsteadAnalyzer added in v1.2.0

func NewHalsteadAnalyzer() *HalsteadAnalyzer

NewHalsteadAnalyzer creates a new Halstead analyzer.

func (*HalsteadAnalyzer) AnalyzeNode added in v1.2.0

func (h *HalsteadAnalyzer) AnalyzeNode(node *sitter.Node, source []byte, lang parser.Language) *models.HalsteadMetrics

AnalyzeNode analyzes a tree-sitter node for Halstead metrics.

func (*HalsteadAnalyzer) Reset added in v1.2.0

func (h *HalsteadAnalyzer) Reset()

Reset clears the analyzer state for a new analysis.

type ProgressFunc

type ProgressFunc func()

ProgressFunc is called after each file is processed.

type SATDAnalyzer

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

SATDAnalyzer detects self-admitted technical debt markers.

func NewSATDAnalyzer

func NewSATDAnalyzer() *SATDAnalyzer

NewSATDAnalyzer creates a new SATD analyzer with default patterns.

func NewSATDAnalyzerStrict added in v1.2.0

func NewSATDAnalyzerStrict() *SATDAnalyzer

NewSATDAnalyzerStrict creates a strict SATD analyzer that only matches explicit markers with colons (e.g., // TODO:, // FIXME:).

func NewSATDAnalyzerWithOptions added in v1.2.0

func NewSATDAnalyzerWithOptions(opts SATDOptions) *SATDAnalyzer

NewSATDAnalyzerWithOptions creates a SATD analyzer with custom options.

func (*SATDAnalyzer) AddPattern

func (a *SATDAnalyzer) AddPattern(pattern string, category models.DebtCategory, severity models.Severity) error

AddPattern adds a custom SATD detection pattern.

func (*SATDAnalyzer) AdjustSeverityWithContext added in v1.2.0

func (a *SATDAnalyzer) AdjustSeverityWithContext(base models.Severity, ctx *AstContext) models.Severity

AdjustSeverityWithContext modifies severity based on AST context. Matches PMAT's adjust_severity method: - SecurityFunction/DataValidation: escalate severity - TestFunction/MockImplementation: reduce severity - Regular with complexity > 20: escalate severity

func (*SATDAnalyzer) AnalyzeFile

func (a *SATDAnalyzer) AnalyzeFile(path string) ([]models.TechnicalDebt, error)

AnalyzeFile scans a file for SATD markers.

func (*SATDAnalyzer) AnalyzeProject

func (a *SATDAnalyzer) AnalyzeProject(files []string) (*models.SATDAnalysis, error)

AnalyzeProject scans all files in a project for SATD using parallel processing.

func (*SATDAnalyzer) AnalyzeProjectWithProgress

func (a *SATDAnalyzer) AnalyzeProjectWithProgress(files []string, onProgress ProgressFunc) (*models.SATDAnalysis, error)

AnalyzeProjectWithProgress scans all files with optional progress callback.

type SATDOptions added in v1.2.0

type SATDOptions struct {
	IncludeTests      bool // Include test files in analysis
	IncludeVendor     bool // Include vendor/third-party files
	AdjustSeverity    bool // Adjust severity based on context
	GenerateContextID bool // Generate context hash for identity tracking
	StrictMode        bool // Only match explicit markers with colons (e.g., // TODO:)
	ExcludeTestBlocks bool // Exclude SATD in Rust #[cfg(test)] blocks
}

SATDOptions configures SATD analysis behavior.

func DefaultSATDOptions added in v1.2.0

func DefaultSATDOptions() SATDOptions

DefaultSATDOptions returns the default options.

type TDGAnalyzer

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

TDGAnalyzer calculates Technical Debt Gradient scores.

func NewTDGAnalyzer

func NewTDGAnalyzer(churnDays int) *TDGAnalyzer

NewTDGAnalyzer creates a new TDG analyzer with default weights.

func (*TDGAnalyzer) AnalyzeProject

func (a *TDGAnalyzer) AnalyzeProject(repoPath string, files []string) (*models.TDGAnalysis, error)

AnalyzeProject calculates TDG scores for a project.

func (*TDGAnalyzer) Close

func (a *TDGAnalyzer) Close()

Close releases analyzer resources.

Jump to

Keyboard shortcuts

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