X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fscripts%2Fjs%2Feslint-stats-by-type.js;fp=web%2Fcore%2Fscripts%2Fjs%2Feslint-stats-by-type.js;h=7ca6a13f4f2add46123bfd553b95e690c7aed866;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/scripts/js/eslint-stats-by-type.js b/web/core/scripts/js/eslint-stats-by-type.js new file mode 100644 index 000000000..7ca6a13f4 --- /dev/null +++ b/web/core/scripts/js/eslint-stats-by-type.js @@ -0,0 +1,35 @@ +module.exports = function (results) { + results = results || []; + + const errorType = { + warnings: {}, + errors: {}, + }; + + results.reduce((result, current) => { + current.messages.forEach((msg) => { + if (msg.severity === 1) { + errorType.warnings[msg.ruleId] = errorType.warnings[msg.ruleId] + 1 || 1 + } + if (msg.severity === 2) { + errorType.errors[msg.ruleId] = errorType.errors[msg.ruleId] + 1 || 1 + } + }); + return result; + }); + + const reduceErrorCounts = (errorType) => Object.entries(errorType).sort((a, b) => b[1] - a[1]) + .reduce((result, current) => result.concat([`${current[0]}: ${current[1]}`]), []).join('\n'); + + const warnings = reduceErrorCounts(errorType.warnings); + const errors = reduceErrorCounts(errorType.errors); + + return ` +Errors: +${'='.repeat(30)} +${errors} +${'\n'.repeat(4)} +Warnings: +${'='.repeat(30)} +${warnings}`; +};