analyzer

package
v1.7.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultCapacity = 100_000

DefaultCapacity for small to medium projects.

View Source
const DefaultGitTimeout = 5 * time.Minute

DefaultGitTimeout is the default timeout for git operations.

View Source
const LargeCapacity = 1_000_000

LargeCapacity for enterprise projects.

Variables

This section is empty.

Functions

func IsTestFile

func IsTestFile(path string) bool

IsTestFile checks if a file is a test file based on naming conventions. Supports Go, Python, JavaScript/TypeScript, Rust, Ruby, Java, and C#.

func IsVendorFile

func IsVendorFile(path string) bool

IsVendorFile checks if a file is in a vendor or third-party directory.

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(opts ...ChurnOption) *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) AnalyzeRepoWithContext

func (a *ChurnAnalyzer) AnalyzeRepoWithContext(ctx context.Context, repoPath string) (*models.ChurnAnalysis, error)

AnalyzeRepoWithContext analyzes git history with a context for cancellation/timeout.

type ChurnOption

type ChurnOption func(*ChurnAnalyzer)

ChurnOption is a functional option for configuring ChurnAnalyzer.

func WithChurnDays

func WithChurnDays(days int) ChurnOption

WithChurnDays sets the number of days to analyze git history.

func WithChurnOpener

func WithChurnOpener(opener vcs.Opener) ChurnOption

WithChurnOpener sets the VCS opener (useful for testing).

func WithChurnSpinner

func WithChurnSpinner(spinner *progress.Tracker) ChurnOption

WithChurnSpinner sets a progress spinner for the analyzer.

type CohesionAnalyzer

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

CohesionAnalyzer computes CK (Chidamber-Kemerer) metrics for OO code.

func NewCohesionAnalyzer

func NewCohesionAnalyzer(opts ...CohesionOption) *CohesionAnalyzer

NewCohesionAnalyzer creates a new CK metrics analyzer.

func (*CohesionAnalyzer) AnalyzeProject

func (a *CohesionAnalyzer) AnalyzeProject(files []string) (*models.CohesionAnalysis, error)

AnalyzeProject computes CK metrics for all OO classes in the project.

func (*CohesionAnalyzer) AnalyzeProjectWithProgress

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

AnalyzeProjectWithProgress computes CK metrics with progress callback.

func (*CohesionAnalyzer) Close

func (a *CohesionAnalyzer) Close()

Close releases resources.

type CohesionOption

type CohesionOption func(*CohesionAnalyzer)

CohesionOption is a functional option for configuring CohesionAnalyzer.

func WithCohesionIncludeTestFiles

func WithCohesionIncludeTestFiles() CohesionOption

WithCohesionIncludeTestFiles includes test files in analysis. By default, test files are skipped.

func WithCohesionMaxFileSize

func WithCohesionMaxFileSize(maxSize int64) CohesionOption

WithCohesionMaxFileSize sets the maximum file size to analyze (0 = no limit).

type ComplexityAnalyzer

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

ComplexityAnalyzer computes cyclomatic and cognitive complexity.

func NewComplexityAnalyzer

func NewComplexityAnalyzer(opts ...ComplexityOption) *ComplexityAnalyzer

NewComplexityAnalyzer creates a new complexity analyzer.

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 ComplexityOption

type ComplexityOption func(*ComplexityAnalyzer)

ComplexityOption is a functional option for configuring ComplexityAnalyzer.

func WithComplexityMaxFileSize

func WithComplexityMaxFileSize(maxSize int64) ComplexityOption

WithComplexityMaxFileSize sets the maximum file size to analyze (0 = no limit).

func WithHalstead added in v1.7.1

func WithHalstead() ComplexityOption

WithHalstead enables Halstead software science metrics calculation.

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(opts ...DeadCodeOption) *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.

type DeadCodeOption

type DeadCodeOption func(*DeadCodeAnalyzer)

DeadCodeOption is a functional option for configuring DeadCodeAnalyzer.

func WithDeadCodeCapacity

func WithDeadCodeCapacity(capacity uint32) DeadCodeOption

WithDeadCodeCapacity sets the initial node capacity.

func WithDeadCodeConfidence

func WithDeadCodeConfidence(confidence float64) DeadCodeOption

WithDeadCodeConfidence sets the confidence threshold (0-1).

func WithDeadCodeCoverage

func WithDeadCodeCoverage(coverage *CoverageData) DeadCodeOption

WithDeadCodeCoverage adds test coverage data for improved accuracy.

func WithDeadCodeMaxFileSize

func WithDeadCodeMaxFileSize(maxSize int64) DeadCodeOption

WithDeadCodeMaxFileSize sets the maximum file size to analyze (0 = no limit).

func WithDeadCodeSkipCallGraph

func WithDeadCodeSkipCallGraph() DeadCodeOption

WithDeadCodeSkipCallGraph disables call graph-based analysis. By default, call graph analysis is enabled.

type DefectAnalyzer

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

DefectAnalyzer predicts defect probability using PMAT weights.

func NewDefectAnalyzer

func NewDefectAnalyzer(opts ...DefectOption) *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 DefectOption

type DefectOption func(*DefectAnalyzer)

DefectOption is a functional option for configuring DefectAnalyzer.

func WithDefectChurnDays

func WithDefectChurnDays(days int) DefectOption

WithDefectChurnDays sets the churn analysis period in days.

func WithDefectMaxFileSize

func WithDefectMaxFileSize(maxSize int64) DefectOption

WithDefectMaxFileSize sets the maximum file size to analyze (0 = no limit).

func WithDefectWeights

func WithDefectWeights(weights models.DefectWeights) DefectOption

WithDefectWeights sets custom PMAT weights for defect prediction.

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(opts ...DuplicateOption) *DuplicateAnalyzer

NewDuplicateAnalyzer creates a new duplicate analyzer with default 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 DuplicateOption

type DuplicateOption func(*DuplicateAnalyzer)

DuplicateOption is a functional option for configuring DuplicateAnalyzer.

func WithDuplicateConfig

func WithDuplicateConfig(cfg config.DuplicateConfig) DuplicateOption

WithDuplicateConfig sets all duplicate configuration from a config struct.

func WithDuplicateMaxFileSize

func WithDuplicateMaxFileSize(maxSize int64) DuplicateOption

WithDuplicateMaxFileSize sets the maximum file size to analyze (0 = no limit).

func WithDuplicateMinTokens

func WithDuplicateMinTokens(minTokens int) DuplicateOption

WithDuplicateMinTokens sets the minimum number of tokens for a code fragment.

func WithDuplicateSimilarityThreshold

func WithDuplicateSimilarityThreshold(threshold float64) DuplicateOption

WithDuplicateSimilarityThreshold sets the similarity threshold for clone detection.

type GraphAnalyzer

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

GraphAnalyzer builds dependency graphs from source code.

func NewGraphAnalyzer

func NewGraphAnalyzer(opts ...GraphOption) *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) CalculatePageRankOnly

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

CalculatePageRankOnly computes only PageRank and degree metrics for fast ranking. Use this when you only need ranking (e.g., repo map) instead of full 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 GraphOption

type GraphOption func(*GraphAnalyzer)

GraphOption is a functional option for configuring GraphAnalyzer.

func WithGraphMaxFileSize

func WithGraphMaxFileSize(maxSize int64) GraphOption

WithGraphMaxFileSize sets the maximum file size to analyze (0 = no limit).

func WithGraphScope

func WithGraphScope(scope GraphScope) GraphOption

WithGraphScope sets the graph node granularity.

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 HotspotAnalyzer

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

HotspotAnalyzer identifies code hotspots using the geometric mean of CDF-normalized churn and complexity scores. This approach:

  • Uses empirical CDFs to normalize metrics against industry benchmarks
  • Applies geometric mean to require BOTH factors to be elevated
  • Produces scores where 0.5+ indicates meaningful hotspots

func NewHotspotAnalyzer

func NewHotspotAnalyzer(opts ...HotspotOption) *HotspotAnalyzer

NewHotspotAnalyzer creates a new hotspot analyzer.

func (*HotspotAnalyzer) AnalyzeProject

func (a *HotspotAnalyzer) AnalyzeProject(repoPath string, files []string) (*models.HotspotAnalysis, error)

AnalyzeProject analyzes hotspots for a project.

func (*HotspotAnalyzer) AnalyzeProjectWithProgress

func (a *HotspotAnalyzer) AnalyzeProjectWithProgress(repoPath string, files []string, onProgress fileproc.ProgressFunc) (*models.HotspotAnalysis, error)

AnalyzeProjectWithProgress analyzes hotspots with optional progress callback.

func (*HotspotAnalyzer) Close

func (a *HotspotAnalyzer) Close()

Close releases analyzer resources.

type HotspotOption

type HotspotOption func(*HotspotAnalyzer)

HotspotOption is a functional option for configuring HotspotAnalyzer.

func WithHotspotChurnDays

func WithHotspotChurnDays(days int) HotspotOption

WithHotspotChurnDays sets the number of days of git history to analyze.

func WithHotspotMaxFileSize

func WithHotspotMaxFileSize(maxSize int64) HotspotOption

WithHotspotMaxFileSize sets the maximum file size to analyze (0 = no limit).

type OwnershipAnalyzer

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

OwnershipAnalyzer calculates code ownership and bus factor.

func NewOwnershipAnalyzer

func NewOwnershipAnalyzer(opts ...OwnershipOption) *OwnershipAnalyzer

NewOwnershipAnalyzer creates a new ownership analyzer.

func (*OwnershipAnalyzer) AnalyzeRepo

func (a *OwnershipAnalyzer) AnalyzeRepo(repoPath string, files []string) (*models.OwnershipAnalysis, error)

AnalyzeRepo analyzes ownership for all files in a repository.

func (*OwnershipAnalyzer) AnalyzeRepoWithProgress

func (a *OwnershipAnalyzer) AnalyzeRepoWithProgress(repoPath string, files []string, onProgress func()) (*models.OwnershipAnalysis, error)

AnalyzeRepoWithProgress analyzes ownership with progress callback.

func (*OwnershipAnalyzer) Close

func (a *OwnershipAnalyzer) Close()

Close releases any resources.

type OwnershipOption

type OwnershipOption func(*OwnershipAnalyzer)

OwnershipOption is a functional option for configuring OwnershipAnalyzer.

func WithOwnershipIncludeTrivial

func WithOwnershipIncludeTrivial() OwnershipOption

WithOwnershipIncludeTrivial includes trivial lines in ownership analysis. By default, trivial lines (empty, braces-only, etc.) are excluded.

func WithOwnershipOpener

func WithOwnershipOpener(opener vcs.Opener) OwnershipOption

WithOwnershipOpener sets the VCS opener (useful for testing).

type RepoMapAnalyzer

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

RepoMapAnalyzer generates a PageRank-ranked map of repository symbols.

func NewRepoMapAnalyzer

func NewRepoMapAnalyzer(opts ...RepoMapOption) *RepoMapAnalyzer

NewRepoMapAnalyzer creates a new repo map analyzer.

func (*RepoMapAnalyzer) AnalyzeProject

func (a *RepoMapAnalyzer) AnalyzeProject(files []string) (*models.RepoMap, error)

AnalyzeProject generates a repo map for the given files.

func (*RepoMapAnalyzer) AnalyzeProjectWithProgress

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

AnalyzeProjectWithProgress generates a repo map with progress callback.

func (*RepoMapAnalyzer) Close

func (a *RepoMapAnalyzer) Close()

Close releases resources.

type RepoMapOption

type RepoMapOption func(*RepoMapAnalyzer)

RepoMapOption is a functional option for configuring RepoMapAnalyzer.

func WithRepoMapMaxFileSize

func WithRepoMapMaxFileSize(maxSize int64) RepoMapOption

WithRepoMapMaxFileSize sets the maximum file size to analyze (0 = no limit).

type SATDAnalyzer

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

SATDAnalyzer detects self-admitted technical debt markers.

func NewSATDAnalyzer

func NewSATDAnalyzer(opts ...SATDOption) *SATDAnalyzer

NewSATDAnalyzer creates a new SATD analyzer with default 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 SATDOption

type SATDOption func(*SATDAnalyzer)

SATDOption is a functional option for configuring SATDAnalyzer.

func WithSATDIncludeTestBlocks

func WithSATDIncludeTestBlocks() SATDOption

WithSATDIncludeTestBlocks includes SATD in Rust #[cfg(test)] blocks. By default, test blocks are excluded.

func WithSATDIncludeVendor

func WithSATDIncludeVendor() SATDOption

WithSATDIncludeVendor includes vendor/third-party files in analysis. By default, vendor files are excluded.

func WithSATDMaxFileSize

func WithSATDMaxFileSize(maxSize int64) SATDOption

WithSATDMaxFileSize sets the maximum file size to analyze (0 = no limit).

func WithSATDSkipSeverityAdjustment

func WithSATDSkipSeverityAdjustment() SATDOption

WithSATDSkipSeverityAdjustment disables context-based severity adjustment. By default, severity is adjusted based on code context.

func WithSATDSkipTests

func WithSATDSkipTests() SATDOption

WithSATDSkipTests excludes test files from analysis. By default, test files are included.

func WithSATDStrictMode

func WithSATDStrictMode() SATDOption

WithSATDStrictMode enables strict mode, matching only explicit markers with colons. By default, relaxed matching is used.

type TdgAnalyzer

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

TdgAnalyzer implements TDG analysis using heuristic methods.

func NewTdgAnalyzer

func NewTdgAnalyzer(opts ...TdgOption) *TdgAnalyzer

NewTdgAnalyzer creates a new TDG analyzer.

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 TdgOption

type TdgOption func(*TdgAnalyzer)

TdgOption is a functional option for configuring TdgAnalyzer.

func WithTdgConfig

func WithTdgConfig(config models.TdgConfig) TdgOption

WithTdgConfig sets the full TDG configuration.

func WithTdgMaxFileSize

func WithTdgMaxFileSize(maxSize int64) TdgOption

WithTdgMaxFileSize sets the maximum file size to analyze (0 = no limit).

type TemporalCouplingAnalyzer

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

TemporalCouplingAnalyzer identifies files that frequently change together.

func NewTemporalCouplingAnalyzer

func NewTemporalCouplingAnalyzer(days, minCochanges int, opts ...TemporalOption) *TemporalCouplingAnalyzer

NewTemporalCouplingAnalyzer creates a new temporal coupling analyzer.

func (*TemporalCouplingAnalyzer) AnalyzeRepo

AnalyzeRepo analyzes temporal coupling for a repository.

func (*TemporalCouplingAnalyzer) AnalyzeRepoWithContext

func (a *TemporalCouplingAnalyzer) AnalyzeRepoWithContext(ctx context.Context, repoPath string) (*models.TemporalCouplingAnalysis, error)

AnalyzeRepoWithContext analyzes temporal coupling with a context for cancellation/timeout.

func (*TemporalCouplingAnalyzer) Close

func (a *TemporalCouplingAnalyzer) Close()

Close releases any resources.

type TemporalOption

type TemporalOption func(*TemporalCouplingAnalyzer)

TemporalOption is a functional option for configuring TemporalCouplingAnalyzer.

func WithTemporalOpener

func WithTemporalOpener(opener vcs.Opener) TemporalOption

WithTemporalOpener sets the VCS opener (useful for testing).

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