Skip to content

Instantly share code, notes, and snippets.

@craigbilner
Last active May 10, 2021 13:19
Show Gist options
  • Save craigbilner/371cb4b98b6de206a8a05bdaa9d31b25 to your computer and use it in GitHub Desktop.
Save craigbilner/371cb4b98b6de206a8a05bdaa9d31b25 to your computer and use it in GitHub Desktop.
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