From fb20bc4030045ff00327efb2b701b771411e76f8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 30 Apr 2022 10:28:42 -0700 Subject: [PATCH] [Refactor] `role-supports-aria-props`: clean up the logic a bit --- src/rules/role-supports-aria-props.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/rules/role-supports-aria-props.js b/src/rules/role-supports-aria-props.js index 9bfdd0f96..ec961032f 100644 --- a/src/rules/role-supports-aria-props.js +++ b/src/rules/role-supports-aria-props.js @@ -42,10 +42,10 @@ export default { schema: [schema], }, - create: (context) => { + create(context) { const elementType = getElementType(context); return { - JSXOpeningElement: (node) => { + JSXOpeningElement(node) { // If role is not explicitly defined, then try and get its implicit role. const type = elementType(node); const role = getProp(node.attributes, 'role'); @@ -66,17 +66,13 @@ export default { const { props: propKeyValues, } = roles.get(roleValue); - const propertySet = Object.keys(propKeyValues); const invalidAriaPropsForRole = [...aria.keys()] - .filter((attribute) => propertySet.indexOf(attribute) === -1); - - node.attributes.forEach((prop) => { - // Ignore the attribute if its value is null or undefined. - if (getPropValue(prop) == null) return; - - // Ignore the attribute if it's a spread. - if (prop.type === 'JSXSpreadAttribute') return; + .filter((attribute) => !(attribute in propKeyValues)); + node.attributes.filter((prop) => ( + getPropValue(prop) != null // Ignore the attribute if its value is null or undefined. + && prop.type !== 'JSXSpreadAttribute' // Ignore the attribute if it's a spread. + )).forEach((prop) => { const name = propName(prop); if (invalidAriaPropsForRole.indexOf(name) > -1) { context.report({