'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var fs_fs = require('../fs/fs.js');
require('../nodejs/crypto.js');
require('../nodejs/fs.js');
require('../nodejs/os.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);

function parseEslintError(_ref) {
  var lintReportFile = _ref.lintReportFile;
  var report = fs_fs.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__default["default"](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
  };
}

exports.parseEslintError = parseEslintError;
