(content)
| 42 | } |
| 43 | |
| 44 | export function countLoc(content) { |
| 45 | let code = 0, comments = 0, inBlock = false; |
| 46 | const lines = content.split(/\r?\n/); |
| 47 | for (const line of lines) { |
| 48 | const s = line.trim(); |
| 49 | if (!s) { comments++; continue; } |
| 50 | if (inBlock) { comments++; if (s.includes('*/')) inBlock = false; continue; } |
| 51 | if (s.startsWith('//')) { comments++; continue; } |
| 52 | if (s.startsWith('/*')) { comments++; if (!s.includes('*/')) inBlock = true; continue; } |
| 53 | code++; |
| 54 | } |
| 55 | comments--; // end of file newline |
| 56 | return { code, comments }; |
| 57 | } |
| 58 | |
| 59 | function normalizeContentForHash(content) { |
| 60 | return content.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); |
no test coverage detected