UNPKG

agentsqripts

Version:

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

69 lines (62 loc) 2.43 kB
/** * @file Large inline object detector * @description Detects large inline objects and strings */ // Precompiled regex pattern for performance optimization const LARGE_OBJECT_PATTERN = /{[\s\S]{500,}}/; /** * Detects large inline objects and strings * @param {string} content - File content * @param {string} filePath - Path to the file * @returns {Array} Array of large inline object issues */ function detectLargeInlineObjects(content, filePath) { const issues = []; const lines = content.split('\n'); const { PERFORMANCE_PATTERNS } = require('./performancePatterns'); lines.forEach((line, index) => { const lineNumber = index + 1; // Check for very long lines (potential large inline objects) if (line.length > 1000) { const pattern = PERFORMANCE_PATTERNS['large_inline']; issues.push({ type: 'large_inline', severity: pattern.severity, category: pattern.category, location: `${filePath}:${lineNumber}`, line: lineNumber, size: line.length, code: line.substring(0, 100) + (line.length > 100 ? '...' : ''), description: `Inlined string/object > ${Math.round(line.length/1000)}kB — may hurt memory/gc`, summary: `Inlined string/object > ${Math.round(line.length/1000)}kB — may hurt memory/gc`, recommendation: 'Move to static asset, external file, or cache layer', effort: pattern.effort, impact: pattern.impact, estimatedSavings: 'up to 90% memory savings' }); } // Check for large object literals using precompiled pattern if (LARGE_OBJECT_PATTERN.test(line)) { const pattern = PERFORMANCE_PATTERNS['large_inline']; issues.push({ type: 'large_inline', severity: pattern.severity, category: pattern.category, location: `${filePath}:${lineNumber}`, line: lineNumber, size: line.length, code: line.substring(0, 100) + '...', description: 'Large object literal detected — may impact memory usage', summary: 'Large object literal detected — may impact memory usage', recommendation: 'Consider moving to external configuration or lazy loading', effort: pattern.effort, impact: pattern.impact, estimatedSavings: 'memory optimization' }); } }); return issues; } module.exports = { detectLargeInlineObjects };