UNPKG

agentsqripts

Version:

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

43 lines (41 loc) 1.92 kB
/** * @file Lines of code counter for precise complexity measurement * @description Single responsibility: Count effective lines of code excluding comments and whitespace for accurate complexity assessment * * This utility provides accurate lines of code (LOC) counting that supports complexity analysis * by measuring the actual volume of executable code. It implements intelligent filtering to * exclude comments, empty lines, and whitespace-only lines, providing a clean metric that * correlates with maintenance effort and implementation complexity. * * Design rationale: * - Comment-aware filtering ensures accurate measurement of executable code volume * - Whitespace exclusion provides cleaner metrics that reflect actual implementation effort * - Simple line-by-line processing maintains efficiency for large file analysis * - Trimmed line analysis handles diverse code formatting styles consistently * - Accurate LOC measurement supports meaningful complexity correlation analysis * * Counting methodology: * - Empty line filtering removes lines with no meaningful content * - Comment line detection excludes both single-line and multi-line comment patterns * - Whitespace trimming handles diverse indentation and formatting styles * - Incremental counting provides efficient processing for large files * - Conservative approach ensures meaningful code volume measurement */ /** * Counts lines of code (excluding comments and empty lines) * @param {string[]} lines - Array of code lines * @returns {number} Lines of code count */ function countLinesOfCode(lines) { return lines.filter(line => { const trimmed = line.trim(); return trimmed.length > 0 && !trimmed.startsWith('//') && !trimmed.startsWith('/*') && !trimmed.startsWith('*') && !trimmed.startsWith('#'); }).length; } module.exports = { countLinesOfCode };