Comparing version 6.0.1 to 6.1.0
@@ -13,4 +13,6 @@ #!/usr/bin/env node | ||
const programOptions = program.opts(); | ||
configureProgram(); | ||
if (program.environment) { | ||
if (programOptions.environment) { | ||
outputEnvironmentInfo(); | ||
@@ -129,3 +131,3 @@ } else { | ||
options.log = report.log; | ||
if (!program.debug) { | ||
if (!programOptions.debug) { | ||
options.log.debug = () => { /* NoOp */ }; | ||
@@ -160,17 +162,17 @@ } | ||
threshold: 0 | ||
}, loadConfig(program.config), { | ||
hideElements: program.hideElements, | ||
ignore: (program.ignore.length ? program.ignore : undefined), | ||
includeNotices: program.includeNotices, | ||
includeWarnings: program.includeWarnings, | ||
level: program.level, | ||
reporter: program.reporter, | ||
runners: (program.runner.length ? program.runner : undefined), | ||
rootElement: program.rootElement, | ||
rules: (program.addRule.length ? program.addRule : undefined), | ||
screenCapture: program.screenCapture, | ||
standard: program.standard, | ||
threshold: program.threshold, | ||
timeout: program.timeout, | ||
wait: program.wait | ||
}, loadConfig(programOptions.config), { | ||
hideElements: programOptions.hideElements, | ||
ignore: (programOptions.ignore.length ? programOptions.ignore : undefined), | ||
includeNotices: programOptions.includeNotices, | ||
includeWarnings: programOptions.includeWarnings, | ||
level: programOptions.level, | ||
reporter: programOptions.reporter, | ||
runners: (programOptions.runner.length ? programOptions.runner : undefined), | ||
rootElement: programOptions.rootElement, | ||
rules: (programOptions.addRule.length ? programOptions.addRule : undefined), | ||
screenCapture: programOptions.screenCapture, | ||
standard: programOptions.standard, | ||
threshold: programOptions.threshold, | ||
timeout: programOptions.timeout, | ||
wait: programOptions.wait | ||
}); | ||
@@ -177,0 +179,0 @@ return options; |
'use strict'; | ||
const extend = require('node.extend'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
@@ -82,5 +83,6 @@ | ||
/** | ||
* Sanitize a URL, ensuring it has a scheme. If the URL begins with a slash or a period, | ||
* it will be resolved as a path against the current working directory. If the URL does | ||
* begin with a scheme, it will be prepended with "http://". | ||
* Sanitize a URL, ensuring it has a scheme. If the URL begins with a slash or a period | ||
* or it is a valid path relative to the current directory, it will be resolved as a | ||
* path against the current working directory. If the URL does begin with a scheme, it | ||
* will be prepended with "http://". | ||
* @private | ||
@@ -91,12 +93,9 @@ * @param {String} url - The URL to sanitize. | ||
function sanitizeUrl(url) { | ||
if (/^\//i.test(url)) { | ||
return `file://${url}`; | ||
let sanitizedUrl = url; | ||
if (/^[./]/i.test(url) || fs.existsSync(url)) { | ||
sanitizedUrl = `file://${path.resolve(process.cwd(), url)}`; | ||
} else if (!/^(https?|file):\/\//i.test(url)) { | ||
sanitizedUrl = `http://${url}`; | ||
} | ||
if (/^\./i.test(url)) { | ||
return `file://${path.resolve(process.cwd(), url)}`; | ||
} | ||
if (!/^(https?|file):\/\//i.test(url)) { | ||
return `http://${url}`; | ||
} | ||
return url; | ||
return sanitizedUrl; | ||
} |
@@ -443,3 +443,3 @@ 'use strict'; | ||
standard: 'WCAG2AA', | ||
timeout: 30000, | ||
timeout: 60000, | ||
userAgent: `pa11y/${pkg.version}`, | ||
@@ -446,0 +446,0 @@ viewport: { |
@@ -75,6 +75,8 @@ 'use strict'; | ||
} | ||
if (Array.isArray(options.rules)) { | ||
axeOptions.rules = pa11yRulesToAxe(); | ||
} | ||
axeOptions.rules = pa11yRulesToAxe( | ||
Array.isArray(options.rules) ? options.rules : [], | ||
Array.isArray(options.ignore) ? options.ignore : [] | ||
); | ||
return axeOptions; | ||
@@ -90,7 +92,2 @@ } | ||
switch (options.standard) { | ||
case 'Section508': | ||
return { | ||
type: 'tags', | ||
values: ['section508', 'best-practice'] | ||
}; | ||
case 'WCAG2A': | ||
@@ -113,7 +110,21 @@ return { | ||
* Map the Pa11y rules option to the aXe rules option. | ||
* @private | ||
* @param {Array} rules - pa11y rules array | ||
* @param {Array} ignore - pa11y ignore array | ||
* @returns {Object} Returns the aXe rules value. | ||
*/ | ||
function pa11yRulesToAxe() { | ||
function pa11yRulesToAxe(rules, ignore) { | ||
const axeRuleIds = window.axe.getRules().reduce((allRules, rule) => { | ||
allRules[rule.ruleId.toLowerCase()] = true; | ||
return allRules; | ||
}, {}); | ||
const axeRules = {}; | ||
options.rules.forEach(rule => (axeRules[rule] = {enabled: true})); | ||
// Filter the rules based on the axeRuleIds then enable/disable them | ||
rules.filter(rule => axeRuleIds[rule]) | ||
.forEach(rule => (axeRules[rule] = {enabled: true})); | ||
ignore.filter(rule => axeRuleIds[rule]) | ||
.forEach(rule => (axeRules[rule] = {enabled: false})); | ||
return axeRules; | ||
@@ -161,5 +172,5 @@ } | ||
return elements.map(element => ({ | ||
type: axeImpactToPa11yLevel(axeIssue.impact), | ||
code: axeIssue.id, | ||
message: `${axeIssue.help} (${axeIssue.helpUrl})`, | ||
type: axeIssue.type, | ||
element, | ||
@@ -189,2 +200,23 @@ runnerExtras: { | ||
/** | ||
* Convert a axe violation impact to a pa11y level | ||
* @private | ||
* @param {string} impact axe level | ||
* @returns {string} pa11y level | ||
*/ | ||
function axeImpactToPa11yLevel(impact) { | ||
switch (impact) { | ||
case 'critical': | ||
case 'serious': | ||
return 'error'; | ||
case 'moderate': | ||
return 'warning'; | ||
case 'minor': | ||
return 'notice'; | ||
default: | ||
return 'error'; | ||
} | ||
} | ||
}; |
@@ -51,9 +51,11 @@ 'use strict'; | ||
function configureHtmlCodeSniffer() { | ||
if (options.rules.length && options.standard !== 'Section508') { | ||
for (const rule of options.rules) { | ||
if (window.HTMLCS_WCAG2AAA.sniffs.includes(rule)) { | ||
window[`HTMLCS_${options.standard}`].sniffs[0].include.push(rule); | ||
} else { | ||
throw new Error(`${rule} is not a valid WCAG 2.0 rule`); | ||
} | ||
if (!options.rules.length || options.standard === 'Section508') { | ||
return; | ||
} | ||
for (const rule of options.rules) { | ||
if (window.HTMLCS_WCAG2AAA.sniffs.includes(rule)) { | ||
window[`HTMLCS_${options.standard}`].sniffs[0].include.push(rule); | ||
} else { | ||
throw new Error(`${rule} is not a valid WCAG 2.1 rule`); | ||
} | ||
@@ -60,0 +62,0 @@ } |
{ | ||
"name": "pa11y", | ||
"version": "6.0.1", | ||
"version": "6.1.0", | ||
"description": "Pa11y is your automated accessibility testing pal", | ||
@@ -37,4 +37,5 @@ "keywords": [ | ||
"bfj": "~7.0.2", | ||
"commander": "~6.2.1", | ||
"commander": "~8.0.0", | ||
"envinfo": "~7.8.1", | ||
"hogan.js": "^3.0.2", | ||
"html_codesniffer": "^2.5.1", | ||
@@ -41,0 +42,0 @@ "kleur": "~4.1.4", |
@@ -147,3 +147,3 @@ # Pa11y | ||
-S, --screen-capture <path> a path to save a screen capture of the page to | ||
-A, --add-rule <rule> WCAG 2.0 rules to include, a repeatable value or separated by semi-colons – only used by htmlcs runner | ||
-A, --add-rule <rule> WCAG 2.1 rules to include, a repeatable value or separated by semi-colons – only used by htmlcs runner | ||
-h, --help output usage information | ||
@@ -639,3 +639,3 @@ ``` | ||
An array of WCAG 2.0 guidelines that you'd like to include to the current standard. You can find the codes for each guideline in the [HTML Code Sniffer WCAG2AAA ruleset][htmlcs-wcag2aaa-ruleset]. **Note:** only used by htmlcs runner. | ||
An array of WCAG 2.1 guidelines that you'd like to include to the current standard. You can find the codes for each guideline in the [HTML Code Sniffer WCAG2AAA ruleset][htmlcs-wcag2aaa-ruleset]. **Note:** only used by htmlcs runner. | ||
@@ -1024,3 +1024,3 @@ ```js | ||
[brew]: https://mxcl.github.com/homebrew/ | ||
[htmlcs-wcag2aaa-ruleset]: https://github.com/pa11y/pa11y/wiki/HTML-CodeSniffer-Rules | ||
[htmlcs-wcag2aaa-ruleset]: https://squizlabs.github.io/HTML_CodeSniffer/Standards/WCAG2/ | ||
[htmlcs]: https://squizlabs.github.io/HTML_CodeSniffer/ | ||
@@ -1027,0 +1027,0 @@ [info-build]: https://github.com/pa11y/pa11y.github.io/actions/workflows/build-and-test.yml |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116921
18
1829
11
8
+ Addedhogan.js@^3.0.2
+ Addedabbrev@1.1.1(transitive)
+ Addedcommander@8.0.0(transitive)
+ Addedhogan.js@3.0.2(transitive)
+ Addedmkdirp@0.3.0(transitive)
+ Addednopt@1.0.10(transitive)
- Removedcommander@6.2.1(transitive)
Updatedcommander@~8.0.0