Skip to content

Instantly share code, notes, and snippets.

@SgtPooki
Last active August 29, 2015 14:05
Show Gist options
  • Save SgtPooki/f13f24517b7a69b93017 to your computer and use it in GitHub Desktop.
Save SgtPooki/f13f24517b7a69b93017 to your computer and use it in GitHub Desktop.
a reporter for node-jscs
/**
* @author Russell Dempsey <rdempsey@nerdery.com>
*/
"use strict";
module.exports = function(errorsCollection) {
var
ruleName,
ruleCountObj,
numberOfFiles,
numberOfErrors,
totalErrors = 0,
totalFiles = 0,
ruleCount = {},
Table = require('cli-table'),
table = new Table({
head: [
"Rule",
"Total Errors",
"Files With Errors"
],
colAligns: [
"middle",
"middle",
"middle"
],
style: {
"padding-left": 0,
"padding-right": 0,
head: ["yellow"],
border: ["red"],
compact: false
}
}),
;
errorsCollection.forEach(function(errors) {
var file = errors.getFilename();
if (!errors.isEmpty()) {
errors.getErrorList().forEach(function(error) {
totalErrors++;
if(!ruleCount[error.rule]) {
ruleCount[error.rule] = {
count: 0,
files: {},
fileCount: 0
};
}
//console.log(error.rule);
ruleCount[error.rule].count++;
if (!ruleCount[error.rule].files[file]) {
ruleCount[error.rule].files[file] = true;
ruleCount[error.rule].fileCount++;
totalFiles++;
}
});
}
});
for(ruleName in ruleCount) {
ruleCountObj = ruleCount[ruleName];
numberOfFiles = ruleCountObj.fileCount;
numberOfErrors = ruleCountObj.count;
if (ruleCount.hasOwnProperty(ruleName)) {
table.push([ruleName, numberOfErrors, numberOfFiles]);
}
}
table.push(['All', totalErrors, totalFiles]);
console.log(table.toString());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment