-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
pa11y-utilities.js
45 lines (40 loc) · 1.23 KB
/
pa11y-utilities.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;