UNPKG

agentsqripts

Version:

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

66 lines (58 loc) 1.7 kB
/** * @file Unexported items extraction * @description Extracts unexported functions and classes from file content */ // Import patterns from atomic module const { PATTERNS } = require('./patterns'); /** * Extract unexported functions and classes from file content * @param {string} content - File content * @returns {Array} Array of unexported items */ function extractUnexportedItems(content) { const lines = content.split('\n'); const unexportedItems = []; lines.forEach((line, index) => { // Skip already exported items if (PATTERNS.export.test(line) || PATTERNS.exportDefault.test(line)) { return; } // Check for function declarations const functionMatch = line.match(PATTERNS.functionDeclaration); if (functionMatch) { unexportedItems.push({ type: 'function', name: functionMatch[1], line: index + 1, declarationType: 'function', content: line.trim() }); } // Check for arrow functions (const name = () => {}) const arrowMatch = line.match(PATTERNS.arrowFunction); if (arrowMatch) { unexportedItems.push({ type: 'function', name: arrowMatch[1], line: index + 1, declarationType: 'const', content: line.trim() }); } // Check for class declarations const classMatch = line.match(PATTERNS.classDeclaration); if (classMatch) { unexportedItems.push({ type: 'class', name: classMatch[1], line: index + 1, declarationType: 'class', content: line.trim() }); } }); return unexportedItems; } module.exports = { extractUnexportedItems };