eslint-stats-by-type.js 899 B

1234567891011121314151617181920212223242526272829303132333435
  1. module.exports = function (results) {
  2. results = results || [];
  3. const errorType = {
  4. warnings: {},
  5. errors: {},
  6. };
  7. results.reduce((result, current) => {
  8. current.messages.forEach((msg) => {
  9. if (msg.severity === 1) {
  10. errorType.warnings[msg.ruleId] = errorType.warnings[msg.ruleId] + 1 || 1
  11. }
  12. if (msg.severity === 2) {
  13. errorType.errors[msg.ruleId] = errorType.errors[msg.ruleId] + 1 || 1
  14. }
  15. });
  16. return result;
  17. });
  18. const reduceErrorCounts = (errorType) => Object.entries(errorType).sort((a, b) => b[1] - a[1])
  19. .reduce((result, current) => result.concat([`${current[0]}: ${current[1]}`]), []).join('\n');
  20. const warnings = reduceErrorCounts(errorType.warnings);
  21. const errors = reduceErrorCounts(errorType.errors);
  22. return `
  23. Errors:
  24. ${'='.repeat(30)}
  25. ${errors}
  26. ${'\n'.repeat(4)}
  27. Warnings:
  28. ${'='.repeat(30)}
  29. ${warnings}`;
  30. };