UNPKG

sicua

Version:

A tool for analyzing project structure and dependencies

103 lines (102 loc) 3.18 kB
import { ScanResult, ComponentRelation } from "../../../types"; export interface ComponentComplexityMetrics { cyclomaticComplexity: number; cognitiveComplexity: number; maintainabilityIndex: number; componentComplexity: number; couplingDegree: number; } export interface ComplexityCalculationResult { componentComplexity: { [key: string]: number; }; couplingDegree: { [key: string]: number; }; cyclomaticComplexity: { [key: string]: number; }; maintainabilityIndex: { [key: string]: number; }; cognitiveComplexity: { [key: string]: number; }; } /** * Unified complexity calculator that processes each file once and calculates all metrics * Uses existing parsed source files and optimized lookup services */ export declare class UnifiedComplexityCalculator { private scanResult; constructor(scanResult: ScanResult); /** * Calculate all complexity metrics in a single pass with component filtering */ calculateAllMetrics(components: ComponentRelation[]): ComplexityCalculationResult; private groupComponentsByFile; /** * Process all AST-based metrics for a single file */ private processFileMetrics; /** * Find component nodes in source file (single traversal) */ private findComponentNodes; /** * Calculate all metrics for a single component node */ private calculateNodeMetrics; /** * Calculate cyclomatic complexity for a node */ private calculateCyclomaticComplexity; /** * Calculate cognitive complexity for a node */ private calculateCognitiveComplexity; /** * Calculate maintainability index using the Microsoft normalized formula: * MI = MAX(0, (171 - 5.2 * ln(HV) - 0.23 * CC - 16.2 * ln(LOC)) * 100 / 171) * Range: 0-100 where higher is better */ private calculateMaintainabilityIndex; /** * Apply maintainability adjustments based on component characteristics * Adjustments are applied to the normalized 0-100 scale */ private applyMaintainabilityAdjustments; /** * Calculate Halstead metrics for a node */ private calculateHalsteadMetrics; /** * Compute maintainability index using standard formula */ private computeMaintainabilityIndex; /** * Calculate component complexity (non-AST based) */ private calculateComponentComplexity; /** * Calculate coupling degree with proper normalization */ /** * Calculate coupling degree using the proper software engineering formula: * C = 1 - 1/(di + 2×ci + do + 2×co + gd + 2×gc + w + r) * Range: ~0.67 (low coupling) to 1.0 (highly coupled) */ private calculateCouplingDegree; /** * Determine if a prop is a control parameter (callback, handler, function) */ private isControlParameter; /** * Determine if an export is a control export (function, handler) */ private isControlExport; /** * Analyze global coupling by examining content for global variable usage */ private analyzeGlobalCoupling; }