UNPKG

agentsqripts

Version:

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

34 lines (28 loc) 884 B
/** * @file Get line number from AST node * @description Single responsibility: Extract line number from an AST node */ /** * Get the line number from an AST node * @param {Object} node - AST node * @returns {number} Line number or 0 if not found */ function getNodeLine(node) { if (!node) return 0; // Check for loc property (most common) if (node.loc && node.loc.start && typeof node.loc.start.line === 'number') { return node.loc.start.line; } // Check for line property directly if (typeof node.line === 'number') { return node.line; } // Check for start property if (typeof node.start === 'number') { // For acorn, we might need to calculate line from position // This is a fallback - ideally loc should be available return 1; // Default to line 1 if we only have position } return 0; } module.exports = getNodeLine;