Skip to content

Commit 3a42eb5

Browse files
authored
Added option to ignore guideline codes and types (#76)
* added extra feature for ignoring guidelines and associated docs * Update manifest.yml
1 parent 9b51de0 commit 3a42eb5

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ If you want to use the plugin's default settings (check **all** pages of your si
9292
If you've installed the plugin via `netlify.toml`, you can add a `[[plugins.inputs]]` field to change how the plugin behaves. This table outlines the inputs the plugin accepts. All of them are optional.
9393

9494

95-
| Input name | Description | Value type | Possible values | Default value |
96-
|---------------------|-----------------------------------------------------------|-----------------------|-------------------------------------------------------|---------------|
97-
| `checkPaths` | Indicates which pages of your site to check | Array of strings | Any directories or HTML files in your project | `['/']` |
98-
| `failWithIssues` | Whether the build should fail if a11y issues are found | Boolean | `true` or `false` | `true` |
99-
| `ignoreDirectories` | Directories that *should not* be checked for a11y issues | Array of strings | Any directories in your project | `[]` |
100-
| `ignoreElements` | Indicates elements that should be ignored by a11y testing | String (CSS selector) | Comma-separated string of CSS selectors | `undefined` |
101-
| `wcagLevel` | The WCAG standard level against which pages are checked | String | `'WCAG2A'` or `'WCAGA2A'` or `'WCAG2AAA'` | `'WCAG2AA'` |
95+
| Input name | Description | Value type | Possible values | Default value |
96+
| ------------------- | ---------------------------------------------------------------------------------------------------- | --------------------- | --------------------------------------------- | ------------- |
97+
| `checkPaths` | Indicates which pages of your site to check | Array of strings | Any directories or HTML files in your project | `['/']` |
98+
| `failWithIssues` | Whether the build should fail if a11y issues are found | Boolean | `true` or `false` | `true` |
99+
| `ignoreDirectories` | Directories that *should not* be checked for a11y issues | Array of strings | Any directories in your project | `[]` |
100+
| `ignoreElements` | Indicates elements that should be ignored by a11y testing | String (CSS selector) | Comma-separated string of CSS selectors | `undefined` |
101+
| `ignoreGuidelines` | Indicates guidelines and types to ignore ([pa11y docs](https://github.com/pa11y/pa11y#ignore-array)) | Array of strings | Comma-separated string of WCAG Guidlines | `[]` |
102+
| `wcagLevel` | The WCAG standard level against which pages are checked | String | `'WCAG2A'` or `'WCAGA2A'` or `'WCAG2AAA'` | `'WCAG2AA'` |
102103

103104
Here's how these inputs can be used in `netlify.toml`, with comments to explain how each input affects the plugin's behavior:
104105

@@ -114,6 +115,8 @@ Here's how these inputs can be used in `netlify.toml`, with comments to explain
114115
ignoreDirectories = ['/admin']
115116
# Ignore any accessibility issues associated with an element matching this selector
116117
ignoreElements = '.jumbotron > h2'
118+
# Ignore any accessibility issues associated with this rule code or type
119+
ignoreGuidelines = ['WCAG2AA.Principle1.Guideline1_4.1_4_6.G17']
117120
# Perform a11y check against WCAG 2.1 AAA
118121
wcagLevel = 'WCAG2AAA'
119122
```

manifest.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ inputs:
1111
description: Array of directories whose pages the plugin should ignore when checking for a11y issues. Defaults to [].
1212
- name: ignoreElements
1313
description: A CSS selector to ignore elements when testing. Accepts multiple comma-separated selectors.
14+
- name: ignoreGuidelines
15+
description: Ignore any accessibility issues associated with this rule code or type. Accepts multiple comma-separated rules.
1416
- name: wcagLevel
1517
default: 'WCAG2AA'
1618
description: The level of WCAG 2.1 against which to check site pages. Defaults to 'WCAGAA'; can also be 'WCAGA' or 'WCAGAAA'.

src/config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ type InputT = {
77
checkPaths?: string[],
88
ignoreDirectories?: string[],
99
ignoreElements?: string,
10+
ignoreGuidelines?: string[],
1011
failWithIssues?: boolean,
11-
wcagLevel?: WCAGLevel
12+
wcagLevel?: WCAGLevel,
1213
}
1314

1415
const DEFAULT_CHECK_PATHS = ['/']
@@ -23,14 +24,15 @@ export const getConfiguration = async ({
2324
constants: { PUBLISH_DIR },
2425
inputs,
2526
}: Pick<NetlifyPluginOptions, 'constants' | 'inputs'>) => {
26-
const { checkPaths, ignoreDirectories, ignoreElements, failWithIssues, wcagLevel } =
27+
const { checkPaths, ignoreDirectories, ignoreElements, ignoreGuidelines, failWithIssues, wcagLevel } =
2728
inputs as InputT
2829
return {
2930
checkPaths: checkPaths || DEFAULT_CHECK_PATHS,
3031
failWithIssues: failWithIssues ?? DEFAULT_FAIL_WITH_ISSUES,
3132
ignoreDirectories: ignoreDirectories || DEFAULT_IGNORE_DIRECTORIES,
3233
pa11yOpts: await getPa11yOpts({
3334
hideElements: ignoreElements,
35+
ignore: ignoreGuidelines,
3436
standard: wcagLevel || PA11Y_DEFAULT_WCAG_LEVEL,
3537
}),
3638
publishDir: (PUBLISH_DIR || process.env.PUBLISH_DIR) as string,
@@ -39,10 +41,11 @@ export const getConfiguration = async ({
3941

4042
export type Config = ReturnType<typeof getConfiguration>
4143

42-
export const getPa11yOpts = async ({ hideElements, standard }: { hideElements?: string; standard: WCAGLevel }) => {
44+
export const getPa11yOpts = async ({ hideElements, ignore, standard }: { hideElements?: string; ignore?: string[]; standard: WCAGLevel }) => {
4345
return {
4446
browser: await puppeteer.launch({ ignoreHTTPSErrors: true }),
4547
hideElements,
48+
ignore,
4649
runners: PA11Y_RUNNERS,
4750
userAgent: PA11Y_USER_AGENT,
4851
standard,

0 commit comments

Comments
 (0)