var Promise = require('es6-promise').Promise;
var lodash = require('lodash');
var validateWithHtmllint = require('./html/htmllint.js');
var validateWithSlowparse = require('./html/slowparse.js');

function filterErrors(errors) {
  var indexedErrors = lodash(errors).indexBy('reason');

  var suppressedTypes = indexedErrors.
    values().
    map('suppresses').
    flatten().
    value();

  return indexedErrors.omit(suppressedTypes).values().value();
}

module.exports = function(source) {
  return Promise.all([
    validateWithSlowparse(source),
    validateWithHtmllint(source),
  ]).then(function(results) {
    var filteredErrors = filterErrors(lodash.flatten(results));
    return lodash.sortBy(filteredErrors, 'row');
  });
};

@@ -228,21 +228,21 @@
 %7B%0A  var 
-index
+group
 edErrors
@@ -259,21 +259,21 @@
 errors).
-index
+group
 By('reas
@@ -303,21 +303,21 @@
 Types = 
-index
+group
 edErrors
@@ -328,24 +328,39 @@
   values().%0A
+    flatten().%0A
     map('sup
@@ -412,13 +412,13 @@
 urn 
-index
+group
 edEr
@@ -453,16 +453,26 @@
 alues().
+flatten().
 value();

Allow the same error on different lines