analyzer

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCapacity = 100_000

DefaultCapacity for small to medium projects.

View Source
const LargeCapacity = 1_000_000

LargeCapacity for enterprise projects.

Variables

This section is empty.

Functions

This section is empty.

Types

type AstContext

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

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 added in v1.5.0

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.5.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 fileproc.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.5.0

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

ComplexityOptions configures complexity analysis behavior.

func DefaultComplexityOptions added in v1.5.0

func DefaultComplexityOptions() ComplexityOptions

DefaultComplexityOptions returns default complexity analysis options.

type CoverageData

type CoverageData struct {
	CoveredLines    map[string]map[uint32]bool  // file -> line -> covered
	ExecutionCounts map[string]map[uint32]int64 // file -> line -> count
	// contains filtered or unexported fields
}

CoverageData integrates test coverage data from external tools (go test -cover, llvm-cov, etc.). This matches PMAT's CoverageData architecture for improved dead code detection accuracy.

func NewCoverageData

func NewCoverageData() *CoverageData

NewCoverageData creates an empty coverage data structure.

func (*CoverageData) GetExecutionCount

func (c *CoverageData) GetExecutionCount(file string, line uint32) int64

GetExecutionCount returns how many times a line was executed.

func (*CoverageData) IsLineCovered

func (c *CoverageData) IsLineCovered(file string, line uint32) bool

IsLineCovered checks if a line was covered during test execution.

type CrossLangReferenceGraph

type CrossLangReferenceGraph struct {
	Edges     []models.ReferenceEdge
	Nodes     map[uint32]*models.ReferenceNode
	EdgeIndex map[uint32][]int // node -> edge indices (outgoing)
	// contains filtered or unexported fields
}

CrossLangReferenceGraph tracks references across language boundaries. This matches PMAT's CrossLangReferenceGraph architecture.

func NewCrossLangReferenceGraph

func NewCrossLangReferenceGraph() *CrossLangReferenceGraph

NewCrossLangReferenceGraph creates an initialized reference graph.

func (*CrossLangReferenceGraph) AddEdge

func (g *CrossLangReferenceGraph) AddEdge(edge models.ReferenceEdge)

AddEdge adds an edge to the reference graph with indexing.

func (*CrossLangReferenceGraph) AddNode

func (g *CrossLangReferenceGraph) AddNode(node *models.ReferenceNode)

AddNode adds a node to the reference graph.

func (*CrossLangReferenceGraph) GetOutgoingEdges

func (g *CrossLangReferenceGraph) GetOutgoingEdges(nodeID uint32) []models.ReferenceEdge

GetOutgoingEdges returns all edges originating from a node.

type DeadCodeAnalyzer

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

DeadCodeAnalyzer detects unused functions, variables, and unreachable code. Architecture matches PMAT's DeadCodeAnalyzer with: - HierarchicalBitSet for efficient reachability tracking - CrossLangReferenceGraph for cross-language references - VTableResolver for dynamic dispatch resolution - CoverageData for test coverage integration - 4-phase analysis: build_reference_graph -> resolve_dynamic_calls -> mark_reachable -> classify_dead_code

func NewDeadCodeAnalyzer

func NewDeadCodeAnalyzer(confidence float64) *DeadCodeAnalyzer

NewDeadCodeAnalyzer creates a new dead code analyzer with PMAT-compatible architecture.

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 the 4-phase PMAT architecture.

func (*DeadCodeAnalyzer) AnalyzeProjectWithProgress

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

AnalyzeProjectWithProgress analyzes dead code with optional progress callback. Implements PMAT's 4-phase analysis: Phase 1: Build reference graph from AST Phase 2: Resolve dynamic dispatch Phase 3: Mark reachable from entry points Phase 4: Classify dead code by type

func (*DeadCodeAnalyzer) Close

func (a *DeadCodeAnalyzer) Close()

Close releases analyzer resources.

func (*DeadCodeAnalyzer) WithCallGraph added in v1.5.0

func (a *DeadCodeAnalyzer) WithCallGraph(enabled bool) *DeadCodeAnalyzer

WithCallGraph enables or disables call graph-based analysis.

func (*DeadCodeAnalyzer) WithCapacity added in v1.5.0

func (a *DeadCodeAnalyzer) WithCapacity(capacity uint32) *DeadCodeAnalyzer

WithCapacity sets the initial node capacity.

func (*DeadCodeAnalyzer) WithCoverage added in v1.5.0

func (a *DeadCodeAnalyzer) WithCoverage(coverage *CoverageData) *DeadCodeAnalyzer

WithCoverage adds test coverage data for improved accuracy.

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 with LSH for efficient candidate filtering.

func NewDuplicateAnalyzer

func NewDuplicateAnalyzer(minLines int, threshold float64) *DuplicateAnalyzer

NewDuplicateAnalyzer creates a new duplicate analyzer with default config.

func NewDuplicateAnalyzerWithConfig added in v1.5.0

func NewDuplicateAnalyzerWithConfig(cfg config.DuplicateConfig) *DuplicateAnalyzer

NewDuplicateAnalyzerWithConfig creates a new duplicate analyzer with explicit config.

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 fileproc.ProgressFunc) (*models.CloneAnalysis, error)

AnalyzeProjectWithProgress detects code clones with optional progress callback.

func (*DuplicateAnalyzer) Close

func (a *DuplicateAnalyzer) Close()

Close releases analyzer resources.

type DuplicateConfig

type DuplicateConfig struct {
	MinTokens            int
	SimilarityThreshold  float64
	ShingleSize          int
	NumHashFunctions     int
	NumBands             int
	RowsPerBand          int
	NormalizeIdentifiers bool
	NormalizeLiterals    bool
	IgnoreComments       bool
	MinGroupSize         int
}

DuplicateConfig holds duplicate detection configuration (pmat-compatible).

func DefaultDuplicateConfig

func DefaultDuplicateConfig() DuplicateConfig

DefaultDuplicateConfig returns pmat-compatible defaults.

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 fileproc.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 comprehensive graph metrics.

func (*GraphAnalyzer) Close

func (a *GraphAnalyzer) Close()

Close releases analyzer resources.

func (*GraphAnalyzer) DetectCycles

func (a *GraphAnalyzer) DetectCycles(graph *models.DependencyGraph) [][]string

DetectCycles uses gonum's Tarjan SCC to find cycles.

func (*GraphAnalyzer) PruneGraph

func (a *GraphAnalyzer) PruneGraph(graph *models.DependencyGraph, maxNodes, maxEdges int) *models.DependencyGraph

PruneGraph reduces graph size while preserving important nodes using PageRank.

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.5.0

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

HalsteadAnalyzer calculates Halstead software science metrics.

func NewHalsteadAnalyzer added in v1.5.0

func NewHalsteadAnalyzer() *HalsteadAnalyzer

NewHalsteadAnalyzer creates a new Halstead analyzer.

func (*HalsteadAnalyzer) AnalyzeNode added in v1.5.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.5.0

func (h *HalsteadAnalyzer) Reset()

Reset clears the analyzer state for a new analysis.

type HierarchicalBitSet

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

HierarchicalBitSet provides efficient bitmap-based reachability tracking using Roaring bitmaps. This matches PMAT's HierarchicalBitSet architecture for memory-efficient sparse bitset operations.

func NewHierarchicalBitSet

func NewHierarchicalBitSet(capacity uint32) *HierarchicalBitSet

NewHierarchicalBitSet creates a new hierarchical bitset with the given capacity.

func (*HierarchicalBitSet) CountSet

func (h *HierarchicalBitSet) CountSet() uint64

CountSet returns the number of reachable nodes.

func (*HierarchicalBitSet) IsSet

func (h *HierarchicalBitSet) IsSet(index uint32) bool

IsSet checks if a node is reachable.

func (*HierarchicalBitSet) Set

func (h *HierarchicalBitSet) Set(index uint32)

Set marks a node as reachable.

func (*HierarchicalBitSet) SetBatch

func (h *HierarchicalBitSet) SetBatch(indices []uint32)

SetBatch marks multiple nodes as reachable efficiently.

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.5.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.5.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

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 fileproc.ProgressFunc) (*models.SATDAnalysis, error)

AnalyzeProjectWithProgress scans all files with optional progress callback.

type SATDOptions added in v1.5.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.5.0

func DefaultSATDOptions() SATDOptions

DefaultSATDOptions returns the default options.

type TdgAnalyzer

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

TdgAnalyzer implements TDG analysis using heuristic methods.

func NewTdgAnalyzer

func NewTdgAnalyzer() *TdgAnalyzer

NewTdgAnalyzer creates a new TDG analyzer.

func NewTdgAnalyzerWithConfig added in v1.5.0

func NewTdgAnalyzerWithConfig(config models.TdgConfig) *TdgAnalyzer

NewTdgAnalyzerWithConfig creates a TDG analyzer with custom config.

func (*TdgAnalyzer) AnalyzeFile

func (a *TdgAnalyzer) AnalyzeFile(path string) (models.TdgScore, error)

AnalyzeFile analyzes a single file and returns its TDG score.

func (*TdgAnalyzer) AnalyzeProject

func (a *TdgAnalyzer) AnalyzeProject(dir string) (models.ProjectScore, error)

AnalyzeProject analyzes all supported files in a directory.

func (*TdgAnalyzer) AnalyzeProjectWithProgress

func (a *TdgAnalyzer) AnalyzeProjectWithProgress(dir string, onProgress func()) (models.ProjectScore, error)

AnalyzeProjectWithProgress analyzes all supported files with optional progress callback.

func (*TdgAnalyzer) AnalyzeSource

func (a *TdgAnalyzer) AnalyzeSource(source string, language models.Language, filePath string) (models.TdgScore, error)

AnalyzeSource analyzes source code and returns its TDG score.

func (*TdgAnalyzer) Close

func (a *TdgAnalyzer) Close()

Close releases any resources (implements interface compatibility).

func (*TdgAnalyzer) Compare

func (a *TdgAnalyzer) Compare(path1, path2 string) (models.TdgComparison, error)

Compare compares two files or directories.

type VTable

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

VTable represents a virtual method table for dynamic dispatch resolution.

type VTableResolver

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

VTableResolver resolves virtual method calls and interface implementations. This matches PMAT's VTableResolver architecture for accurate dead code detection in OOP languages.

func NewVTableResolver

func NewVTableResolver() *VTableResolver

NewVTableResolver creates a new VTable resolver.

func (*VTableResolver) RegisterImplementation

func (v *VTableResolver) RegisterImplementation(interfaceName, typeName string)

RegisterImplementation records that a type implements an interface.

func (*VTableResolver) RegisterType

func (v *VTableResolver) RegisterType(typeName, baseType string, methods map[string]uint32)

RegisterType registers a type's virtual method table.

func (*VTableResolver) ResolveDynamicCall

func (v *VTableResolver) ResolveDynamicCall(interfaceName, methodName string) []uint32

ResolveDynamicCall returns all possible targets for a dynamic method call.

Jump to

Keyboard shortcuts

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