Skip to content

Commit fb20bc4

Browse files
committedApr 30, 2022
[Refactor] role-supports-aria-props: clean up the logic a bit
1 parent ee933a2 commit fb20bc4

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed
 

Diff for: ‎src/rules/role-supports-aria-props.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export default {
4242
schema: [schema],
4343
},
4444

45-
create: (context) => {
45+
create(context) {
4646
const elementType = getElementType(context);
4747
return {
48-
JSXOpeningElement: (node) => {
48+
JSXOpeningElement(node) {
4949
// If role is not explicitly defined, then try and get its implicit role.
5050
const type = elementType(node);
5151
const role = getProp(node.attributes, 'role');
@@ -66,17 +66,13 @@ export default {
6666
const {
6767
props: propKeyValues,
6868
} = roles.get(roleValue);
69-
const propertySet = Object.keys(propKeyValues);
7069
const invalidAriaPropsForRole = [...aria.keys()]
71-
.filter((attribute) => propertySet.indexOf(attribute) === -1);
72-
73-
node.attributes.forEach((prop) => {
74-
// Ignore the attribute if its value is null or undefined.
75-
if (getPropValue(prop) == null) return;
76-
77-
// Ignore the attribute if it's a spread.
78-
if (prop.type === 'JSXSpreadAttribute') return;
70+
.filter((attribute) => !(attribute in propKeyValues));
7971

72+
node.attributes.filter((prop) => (
73+
getPropValue(prop) != null // Ignore the attribute if its value is null or undefined.
74+
&& prop.type !== 'JSXSpreadAttribute' // Ignore the attribute if it's a spread.
75+
)).forEach((prop) => {
8076
const name = propName(prop);
8177
if (invalidAriaPropsForRole.indexOf(name) > -1) {
8278
context.report({

0 commit comments

Comments
 (0)
Please sign in to comment.