Files
polaris-react/scripts/pa11y-utilities.js
Ben Scott da9344e15b Manually fix several linting issues
Prior to this version of eslint-plugin-shopify some rules were
inadvertently disabled due to ordering of plugins causing prior plugins
to be disabled. This has now been fixed so we can see errors for things
that were problematic.
2018-11-01 16:58:15 -07:00

46 lines
1.2 KiB
JavaScript

const hash = require('object-hash');
function shitlistCheck(results, immutableShitlist) {
const mutableShitlist = {};
const remainingIssues = [];
Object.keys(immutableShitlist).forEach((key) => {
mutableShitlist[key] = Array.from(immutableShitlist[key]);
});
const filteredResults = results.map((result) => {
if (mutableShitlist[result.pageUrl]) {
result.issues = result.issues.filter((issue) => {
const issueHash = hash(issue);
const matchIndex = mutableShitlist[result.pageUrl].findIndex(
(shitlistedResult) => {
return hash(shitlistedResult) === issueHash;
},
);
if (matchIndex >= 0) {
mutableShitlist[result.pageUrl].splice(matchIndex, 1);
}
return matchIndex === -1;
});
}
return result;
});
Object.keys(mutableShitlist).forEach((key) => {
if (mutableShitlist[key].length) {
remainingIssues.push({
pageUrl: key,
issues: mutableShitlist[key],
});
}
});
return {
results: filteredResults.filter((result) => result.issues.length),
remainingIssues: Object.keys(remainingIssues).length
? remainingIssues
: null,
};
}
module.exports.shitlistCheck = shitlistCheck;