Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / core / scripts / js / eslint-stats-by-type.js
1 module.exports = function (results) {
2   results = results || [];
3
4   const errorType = {
5     warnings: {},
6     errors: {},
7   };
8
9   results.reduce((result, current) => {
10     current.messages.forEach((msg) => {
11       if (msg.severity === 1) {
12         errorType.warnings[msg.ruleId] = errorType.warnings[msg.ruleId] + 1 || 1
13       }
14       if (msg.severity === 2) {
15         errorType.errors[msg.ruleId] = errorType.errors[msg.ruleId] + 1 || 1
16       }
17     });
18     return result;
19   });
20
21   const reduceErrorCounts = (errorType) => Object.entries(errorType).sort((a, b) => b[1] - a[1])
22     .reduce((result, current) => result.concat([`${current[0]}: ${current[1]}`]), []).join('\n');
23
24   const warnings = reduceErrorCounts(errorType.warnings);
25   const errors = reduceErrorCounts(errorType.errors);
26
27   return `
28 Errors:
29 ${'='.repeat(30)}
30 ${errors}
31 ${'\n'.repeat(4)}
32 Warnings:
33 ${'='.repeat(30)}
34 ${warnings}`;
35 };