agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
53 lines (46 loc) • 1.8 kB
JavaScript
/**
* @file Method mismatch detector
* @description Detects HTTP method mismatches between frontend and backend
*/
/**
* Detects method mismatches between frontend and backend
* @param {Array} backendEndpoints - Backend endpoints
* @param {Array} frontendCalls - Frontend API calls
* @returns {Array} Array of method mismatch issues
*/
function detectMethodMismatches(backendEndpoints, frontendCalls) {
const issues = [];
const { INTEGRATION_PATTERNS } = require('./integrationPatterns');
// Create optimized lookup map for backend endpoints by route
const endpointsByRoute = new Map();
for (const endpoint of backendEndpoints) {
if (!endpointsByRoute.has(endpoint.route)) {
endpointsByRoute.set(endpoint.route, new Set());
}
endpointsByRoute.get(endpoint.route).add(endpoint.method);
}
for (const call of frontendCalls) {
const availableMethods = endpointsByRoute.get(call.route);
if (availableMethods && !availableMethods.has(call.method)) {
const patternInfo = INTEGRATION_PATTERNS['method_mismatch'];
const methodsArray = Array.from(availableMethods);
issues.push({
type: 'method_mismatch',
severity: patternInfo.severity,
category: patternInfo.category,
location: `${call.file}:${call.line}`,
method: call.method,
route: call.route,
availableMethods: methodsArray,
summary: `Frontend uses [${call.method}] but backend only supports [${methodsArray.join(', ')}] for ${call.route}`,
recommendation: `Change frontend to use ${methodsArray[0]} or add ${call.method} support to backend`,
effort: patternInfo.effort,
impact: patternInfo.impact
});
}
}
return issues;
}
module.exports = {
detectMethodMismatches
};