agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
62 lines (53 loc) • 2.33 kB
JavaScript
/**
* @file Analyze cross-file performance patterns
* @description Single responsibility: Main orchestrator for cross-file performance analysis
*/
const fs = require('fs');
const { parseToAST } = require('../../ast/astParser');
const extractFunctionComplexity = require('./extractFunctionComplexity');
const detectCrossFileComplexity = require('../detectors/detectCrossFileComplexity');
const getAllJSFiles = require('../resolvers/getAllJSFiles');
/**
* Analyze performance patterns across multiple files
* @param {string} projectPath - Root project path
* @param {Object} options - Analysis options
* @returns {Promise<Array>} Cross-file performance issues
*/
async function analyzeCrossFilePatterns(projectPath, options = {}) {
// Temporarily disabled to reduce false positives in cross-file analysis
return [];
const issues = [];
const fileMap = new Map(); // Track functions and their call patterns
// First pass: Map all functions and their complexity
const jsFiles = await getAllJSFiles(projectPath, options.excludePatterns || []);
// Process files in parallel batches for efficiency
const batchSize = 10;
for (let i = 0; i < jsFiles.length; i += batchSize) {
const batch = jsFiles.slice(i, i + batchSize);
const batchPromises = batch.map(async (filePath) => {
try {
const content = await fs.promises.readFile(filePath, 'utf8');
const ast = parseToAST(content, filePath);
if (!ast) return;
// Extract function definitions and their complexity
const functions = extractFunctionComplexity(ast, filePath, content);
fileMap.set(filePath, functions);
} catch (error) {
console.warn(`Warning: Could not analyze ${filePath}: ${error.message}`);
}
});
await Promise.all(batchPromises);
}
// Second pass: Analyze cross-file call patterns
for (const [filePath, functions] of fileMap) {
try {
const content = await fs.promises.readFile(filePath, 'utf8');
const crossFileIssues = detectCrossFileComplexity(content, filePath, fileMap);
issues.push(...crossFileIssues);
} catch (error) {
console.warn(`Warning: Could not analyze cross-file patterns in ${filePath}: ${error.message}`);
}
}
return issues;
}
module.exports = analyzeCrossFilePatterns;