UNPKG

agentsqripts

Version:

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

113 lines (101 loc) 4.75 kB
/** * @file Static bug recommendation generator for actionable fix guidance * @description Single responsibility: Generate prioritized, actionable recommendations for static bug resolution * * This generator transforms static bug detection results into practical, prioritized action * items that development teams can implement to improve code quality. It provides context-aware * recommendations that consider bug severity, fix complexity, and business impact to guide * systematic code quality improvement efforts. * * Design rationale: * - Priority-based recommendations enable teams to focus on highest-impact bug fixes * - Context-aware guidance provides practical implementation steps beyond generic advice * - Effort estimation helps teams plan bug fixing sprints and allocate resources effectively * - Category-specific recommendations provide targeted guidance for different bug types * - Actionable descriptions enable immediate implementation without additional research * * Recommendation framework: * - Logic errors: Code flow analysis, conditional logic fixes, variable scope corrections * - Type issues: Type annotations, validation improvements, casting corrections * - Security vulnerabilities: Input validation, authentication fixes, authorization improvements * - Performance issues: Algorithm optimization, memory usage improvements, I/O efficiency * - Maintainability: Code organization, documentation, naming convention improvements */ /** * Generate bug fix recommendations with detailed guidance * @param {Array} issues - Detected bugs * @param {number} totalEffort - Total effort to fix all issues * @param {number} fileCount - Number of files analyzed * @returns {Array} Bug fix recommendations as objects with priority, fix, and explanation */ function generateBugRecommendations(issues = [], totalEffort = 0, fileCount = 0) { const recommendations = []; if (issues.length === 0) { recommendations.push({ priority: 'low', fix: 'No action needed', explanation: 'No static bugs detected - code quality looks good' }); return recommendations; } const highIssues = issues.filter(i => i.severity === 'HIGH'); const typeCoercionIssues = issues.filter(i => i.type === 'type_coercion'); const errorHandlingIssues = issues.filter(i => i.category === 'Error Handling'); const securityIssues = issues.filter(i => i.category === 'Security'); const nullRefIssues = issues.filter(i => i.type === 'null_reference'); const undefinedVarIssues = issues.filter(i => i.type === 'undefined_variable'); const asyncIssues = issues.filter(i => i.type === 'missing_await'); if (highIssues.length > 0) { recommendations.push({ priority: 'critical', fix: `Fix ${highIssues.length} high-severity bugs immediately`, explanation: 'High-severity bugs can cause runtime failures and should be addressed first' }); } if (nullRefIssues.length > 0) { recommendations.push({ priority: 'high', fix: 'Add null checks before property access', explanation: `${nullRefIssues.length} null reference patterns detected. Add validation like 'if (obj && obj.property)' before accessing properties` }); } if (undefinedVarIssues.length > 0) { recommendations.push({ priority: 'high', fix: 'Declare variables before use', explanation: `${undefinedVarIssues.length} undefined variable patterns detected. Ensure all variables are declared with const, let, or var` }); } if (asyncIssues.length > 0) { recommendations.push({ priority: 'high', fix: 'Add missing await keywords', explanation: `${asyncIssues.length} async patterns detected. Add 'await' before Promise-returning functions like fetch()` }); } if (typeCoercionIssues.length > 0) { recommendations.push({ priority: 'medium', fix: 'Replace == with === for strict equality', explanation: `${typeCoercionIssues.length} type coercion patterns detected. Use === to avoid unexpected type conversions` }); } if (errorHandlingIssues.length > 0) { recommendations.push({ priority: 'medium', fix: 'Add try-catch blocks for error-prone operations', explanation: `${errorHandlingIssues.length} missing error handling patterns detected. Wrap risky operations in try-catch blocks` }); } if (securityIssues.length > 0) { recommendations.push({ priority: 'critical', fix: `Address ${securityIssues.length} security-related issues`, explanation: 'Security vulnerabilities can lead to data breaches and system compromises' }); } return recommendations; } module.exports = { generateBugRecommendations };