From 77f6c878864a57d08ca7d385a21970e0be2377f3 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 3 Dec 2021 11:02:02 -0500 Subject: [PATCH] Add to .md and move up validRoles as a Set --- docs/rules/aria-role.md | 2 +- src/rules/aria-role.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/rules/aria-role.md b/docs/rules/aria-role.md index 89065f863..0167752b0 100644 --- a/docs/rules/aria-role.md +++ b/docs/rules/aria-role.md @@ -17,7 +17,7 @@ This rule takes one optional object argument of type object: } ``` -`allowedInvalidRules` is an optional string array of custom roles that should be allowed in addition to the ARIA spec. +`allowedInvalidRules` is an optional string array of custom roles that should be allowed in addition to the ARIA spec, such as for cases when you [need to use a non-standard role](https://axesslab.com/text-splitting). For the `ignoreNonDOM` option, this determines if developer created components are checked. diff --git a/src/rules/aria-role.js b/src/rules/aria-role.js index 4a2a01e34..83ead048d 100644 --- a/src/rules/aria-role.js +++ b/src/rules/aria-role.js @@ -39,6 +39,7 @@ export default { const options = context.options[0] || {}; const ignoreNonDOM = !!options.ignoreNonDOM; const allowedInvalidRoles = new Set(options.allowedInvalidRoles || []) + const validRoles = [...roles.keys()].filter((role) => roles.get(role).abstract === false); return ({ JSXAttribute: (attribute) => { @@ -63,7 +64,6 @@ export default { if (value === undefined || value === null) { return; } const values = String(value).split(' '); - const validRoles = [...roles.keys()].filter((role) => roles.get(role).abstract === false); const isValid = values.every((val) => allowedInvalidRoles.has(val) || validRoles.indexOf(val) > -1); if (isValid === true) { return; }