Created
December 9, 2018 17:12
-
-
Save dylanb/410c717c628e5301c170780d0e741c1e to your computer and use it in GitHub Desktop.
CLI output for axe-core violations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const colors = require('colors'); | |
const link = colors.underline.blue; | |
const error = colors.red.bold; | |
function selectorToString(selectors, separator) { | |
separator = separator || ' ' | |
return selectors | |
.reduce((prev, curr) => prev.concat(curr), []) | |
.join(separator) | |
} | |
module.exports = function (results, verbose) { | |
const cliReporter = function(...args) { | |
console.log(...args) | |
} | |
const violations = results.violations | |
if (violations.length === 0) { | |
if (verbose) { | |
cliReporter(colors.green(' 0 violations found!')) | |
} | |
return | |
} | |
const issueCount = violations.reduce((count, violation) => { | |
cliReporter( | |
'\n' + | |
' Violation of %j with %d occurrences!\n' + | |
' %s. Correct invalid elements at:\n' + | |
violation.nodes | |
.map(node => ' - ' + selectorToString(node.target) + '\n') | |
.join('') + | |
' For details, see: %s', | |
violation.id, | |
violation.nodes.length, | |
violation.description, | |
link(violation.helpUrl.split('?')[0]) | |
) | |
return count + violation.nodes.length | |
}, 0) | |
cliReporter(error('\n%d Accessibility violations detected.'), issueCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment