agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
35 lines (27 loc) • 963 B
JavaScript
/**
* @file Find common methods across classes
* @description Single responsibility: Identify shared methods in classes
*/
function findCommonMethods(blocks) {
if (!blocks || blocks.length < 2) return [];
// Extract methods from each block
const methodSets = blocks.map(block => {
// If block has methods property, use it
if (block.methods) return new Set(block.methods.map(m => m.name));
// Otherwise try to extract from code
const methodPattern = /^\s*(async\s+)?(\w+)\s*\([^)]*\)\s*\{/gm;
const methods = new Set();
let match;
while ((match = methodPattern.exec(block.code || '')) !== null) {
methods.add(match[2]);
}
return methods;
});
// Find intersection of all method sets
const firstSet = methodSets[0];
const commonMethods = [...firstSet].filter(method =>
methodSets.every(set => set.has(method))
);
return commonMethods;
}
module.exports = findCommonMethods;