How do I add rules to pa11y-ci?

857 Views Asked by At

I need to customize the ruleset used by pa11y. For instance let's say I want to follow WCAG2A but want to add some rules from WCAG2AA.

I tried with something like this for configuration in my .pa11yci-file:

{
"defaults": {
    "standard": "WCAG2A",
    "rules": ["WCAG2AA.Principle1.Guideline1_1.1_1_1.H30.2"],
    "hideElements": "",
    "ignore": [],
    "includeWarnings": true,
    "timeout": 5000,
    "threshold": 0
},
"urls": [
    {
        "url": "https://www.ecster.se",
        "actions": [

        ]
    }]

}

But I only get this in the console:

    Error: Evaluation failed: Error: WCAG2AA.Principle1.Guideline1_1.1_1_1.H30.2 is not a valid WCAG 2.0 rule
   at configureHtmlCodeSniffer (<anonymous>:60:13)
   at runPa11y (<anonymous>:30:3)

I get my rulenames from here: https://github.com/pa11y/pa11y/wiki/HTML-CodeSniffer-Rules

Using latest version of pa11y-ci: 2.1.1.

2

There are 2 best solutions below

2
On

Looking at the Pa11y documentation it looks as though you need to reference rules without the standard.

E.g. Principle1.Guideline1_1.1_1_1.H30.2, not WCAG2AA.Principle1.Guideline1_1.1_1_1.H30.2

Worth noting that that Guideline you've used as an example is already present in both WCAG2A and WCAG2AA. Might be worth trying with one that's only present in AA and above e.g. Principle3.Guideline3_1.3_1_2.H58.1.Lang

2
On

You should have a rules property with an array of rules you wish to include.

...
"rules": [ "standard.you.wish.to.include",...],
...