Skip to content

Commit

Permalink
[Refactor] role-supports-aria-props: clean up the logic a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 30, 2022
1 parent ee933a2 commit fb20bc4
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/rules/role-supports-aria-props.js
Expand Up @@ -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');
Expand All @@ -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({
Expand Down

0 comments on commit fb20bc4

Please sign in to comment.