import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import { readFileSync } from '../fs/fs.mjs';
import '../nodejs/crypto.mjs';
import '../nodejs/fs.mjs';
import '../nodejs/os.mjs';

function parseEslintError(_ref) {
  var lintReportFile = _ref.lintReportFile;
  var report = readFileSync(lintReportFile, true) || {};
  var errors = (report.results || []).filter(function (item) {
    return !!item.errorCount;
  });
  var total = errors.reduce(function (acc, item) {
    return acc + item.errorCount;
  }, 0);
  var errorMap = errors.reduce(function (acc, item) {
    acc.push.apply(acc, _toConsumableArray(item.messages.filter(function (item) {
      return item.severity == 2;
    }).map(function (msg) {
      return Object.assign(Object.assign({}, msg), {
        filePath: item.filePath,
        errorCount: item.errorCount
      });
    })));
    return acc;
  }, []).reduce(function (acc, item) {
    if (!acc[item.ruleId]) {
      item.number = 1;
      acc[item.ruleId] = item;
    } else {
      acc[item.ruleId].number += 1;
    }
    return acc;
  }, {});
  return {
    errorMap: errorMap,
    total: total
  };
}

export { parseEslintError };
