Last active
May 10, 2021 13:19
-
-
Save craigbilner/371cb4b98b6de206a8a05bdaa9d31b25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
fs.readFile('lcov.info', 'utf8', (err, data) => { | |
const arr = data.split('\n'); | |
let file; | |
const counts = []; | |
arr.forEach((a) => { | |
const [id, value] = a.split(':'); | |
if (id === 'SF') { | |
file = value; | |
return; | |
} | |
if (id === 'DA') { | |
const [ln, count] = value.split(','); | |
counts.push({ | |
file, | |
ln, | |
count: parseInt(count, 10), | |
}); | |
} | |
}); | |
counts.sort((a, b) => { | |
if (a.count > b.count) { | |
return -1; | |
} | |
if (a.count < b.count) { | |
return 1; | |
} | |
return 0; | |
}); | |
const strs = counts.map(c => `${c.file},${c.ln},${c.count}`) | |
fs.writeFile('cov.txt', strs.join('\n'), 'utf8', () => | |
console.log('done') | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment