Skip to content

Commit c271843

Browse files
committed
chore: Sort violation logs by impact level
1 parent f7dddf7 commit c271843

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/utils.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import axeCore from 'axe-core'
22

33
let cache = {}
44
let style = {}
5-
const deferred = {}
65
let lastNotification = ''
76

7+
const deferred = {}
8+
const impacts = ['critical', 'serious', 'moderate', 'minor']
9+
810
export function checkAndReport (options, node) {
911
const deferred = createDeferred()
1012
style = { ...options.style }
@@ -40,8 +42,8 @@ const standardResultHandler = function (errorInfo, results) {
4042

4143
if (results.violations.length) {
4244
console.group('%cNew axe issues', style.head)
43-
console.log(results.violations)
44-
results.violations.forEach(result => {
45+
const violations = sortViolations(results.violations)
46+
violations.forEach(result => {
4547
console.groupCollapsed('%c%s%c %s %s %c%s', style[result.impact || 'minor'], result.impact, style.title, result.help, '\n', style.url, result.helpUrl)
4648
result.nodes.forEach(function (node) {
4749
failureSummary(node, 'any')
@@ -61,6 +63,14 @@ export function resetLastNotification () {
6163
lastNotification = ''
6264
}
6365

66+
function sortViolations (violations) {
67+
let sorted = []
68+
impacts.forEach(impact => {
69+
sorted = [...sorted, ...violations.filter(violation => violation.impact === impact)]
70+
})
71+
return sorted
72+
}
73+
6474
function createDeferred () {
6575
deferred.promise = new Promise((resolve, reject) => {
6676
deferred.resolve = resolve

0 commit comments

Comments
 (0)