agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
50 lines (44 loc) • 1.56 kB
JavaScript
/**
* @file Refactoring suggestion generator
* @description Generates specific refactoring suggestions for files
*/
const path = require('path');
/**
* Generate refactoring suggestions for a specific file
* @param {Object} analysis - File analysis results
* @returns {Array} Array of suggestions
*/
function generateRefactoringSuggestions(analysis) {
const suggestions = [];
for (const opp of analysis.promotionOpportunities) {
if (opp.type === 'export_promotion') {
suggestions.push({
type: 'code_change',
description: `Export ${opp.item.type} '${opp.item.name}'`,
currentCode: opp.item.content,
suggestedCode: `export ${opp.item.content}`,
line: opp.item.line,
file: analysis.file
});
} else if (opp.type === 'barrel_file_creation') {
// Build index content without any nested operations
const exports = analysis.existingExports;
const fileName = path.basename(analysis.file, path.extname(analysis.file));
const exportLines = [];
for (let i = 0; i < exports.length; i++) {
exportLines.push(`export { ${exports[i].name} } from './${fileName}';`);
}
const indexContent = exportLines.join('\n');
suggestions.push({
type: 'file_creation',
description: 'Create barrel file for easier imports',
fileName: path.join(path.dirname(analysis.file), 'index.ts'),
content: indexContent
});
}
}
return suggestions;
}
module.exports = {
generateRefactoringSuggestions
};