You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为pa11y-ci添加规则?WCAG规则配置报错排查

Fixing Invalid WCAG Rule Error in pa11y-ci 2.1.1

I ran into this exact issue when mixing WCAG 2A and 2AA rules in pa11y-ci, so I know how frustrating it can be. Here's what's going wrong and how to fix it:

Why You're Seeing the Error

The full rule path you used (WCAG2AA.Principle1.Guideline1_1.1_1_1.H30.2) isn't the format pa11y-ci expects for rule identifiers. While that full hierarchy exists in HTML CodeSniffer's internal structure, pa11y uses simplified, shorthand rule names (like WCAG2AA.H30.2) that skip the principle/guideline/sub-guideline prefixes. That's why the tool is throwing an invalid rule error.

Correct Configuration Approach

To combine WCAG 2A as your base standard plus specific WCAG 2AA rules, use the standard field for your base ruleset and the include array to add your extra AA rules. Here's a working example .pa11yci config:

{
  "urls": [
    "https://your-target-url.com"
  ],
  "standard": "WCAG2A",
  "include": [
    "WCAG2AA.H30.2",
    // Add other WCAG 2AA rules you want here, e.g.:
    "WCAG2AA.H37",
    "WCAG2AA.G18"
  ],
  "exclude": [] // Optional: Add rules you want to omit from the base standard
}

Verify Valid Rule Names

If you're unsure about a rule's correct shorthand name, run this command in your terminal to list all rules supported by your pa11y-ci version:

pa11y --list-rules

This will output every valid rule identifier you can use in your config, so you can cross-check the names you want to add.

Alternative: Explicitly List All Rules

If you prefer to define every rule explicitly (instead of using a base standard), you can list both WCAG 2A and your chosen 2AA rules in the rules array:

{
  "urls": [
    "https://your-target-url.com"
  ],
  "rules": [
    // WCAG 2A rules (example subset)
    "WCAG2A.H25",
    "WCAG2A.G94",
    // WCAG 2AA rules you want to add
    "WCAG2AA.H30.2",
    "WCAG2AA.H37"
  ]
}

Just note that this approach requires you to list every rule you want to enforce, which can be more maintenance-heavy than using the standard + include method.

内容的提问来源于stack exchange,提问作者jBoive

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:37:48