-
-
Save SgtPooki/f13f24517b7a69b93017 to your computer and use it in GitHub Desktop.
a reporter for node-jscs
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
/** | |
* @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