UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

55 lines (52 loc) 2.61 kB
/** * @file Regular expression pattern definitions for comprehensive code structure analysis * @description Single responsibility: Define regex patterns for code element identification and parsing * * This configuration module centralizes regular expression patterns used across multiple * analysis tools for identifying JavaScript code structures, import/export patterns, * function declarations, and module organization elements. It ensures consistent pattern * matching behavior across all analysis components while maintaining high performance. * * Design rationale: * - Centralized patterns prevent regex inconsistencies across analysis tools * - Pre-compiled regex objects optimize performance for repeated pattern matching * - Comprehensive coverage handles modern JavaScript syntax variations * - Whitespace-aware patterns account for different formatting styles * - Capture groups enable extraction of specific code elements for analysis */ // Pattern Constants /** * Comprehensive JavaScript code structure patterns with optimized regex compilation * * Pattern design methodology: * - Leading whitespace handling (^\s*) accommodates various indentation styles * - Capture groups extract specific identifiers for detailed analysis * - Non-greedy matching prevents excessive backtracking on large files * - Escape sequences handle special characters in import paths correctly * * Pattern categories: * - Export patterns: Function, class, named, and default export identification * - Function patterns: Declaration and arrow function extraction with name capture * - Import patterns: Module dependency tracking with path extraction * - Class patterns: Object-oriented structure identification * - Re-export patterns: Module barrel file and aggregation detection * * Performance considerations: * - Static regex compilation avoids runtime compilation overhead * - Optimized quantifiers reduce backtracking in complex code structures * - Character classes improve matching speed over alternations * - Anchored patterns (^) optimize line-by-line analysis performance */ const PATTERNS = { export: /^\s*export\s+(?:function|class)\s+/, exportDefault: /^\s*export\s+default\s+/, exportNamed: /^\s*export\s+\{[^}]+\}\s+from\s+/, functionDeclaration: /^\s*function\s+([a-zA-Z0-9_$]+)\s*\(/, arrowFunction: /^\s*const\s+([a-zA-Z0-9_$]+)\s*=\s*\([^)]*\)\s*=>/, classDeclaration: /^\s*class\s+([a-zA-Z0-9_$]+)/, importStatement: /^\s*import\s+.*from\s+['"]([^'"]+)['"]/, reexport: /^\s*export\s+.*from\s+['"]([^'"]+)['"]/ }; module.exports = { PATTERNS };