Skip to content

Commit

Permalink
[Refactor] remove no-longer-needed es-iterator-helpers
Browse files Browse the repository at this point in the history
aria-query v5 returns arrays now, not iterators
  • Loading branch information
ljharb committed Oct 25, 2024
1 parent e5dda96 commit 697cc90
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 48 deletions.
7 changes: 2 additions & 5 deletions __tests__/src/rules/role-has-required-aria-props-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

import { roles } from 'aria-query';
import { RuleTester } from 'eslint';
import iterFrom from 'es-iterator-helpers/Iterator.from';
import map from 'es-iterator-helpers/Iterator.prototype.map';
import toArray from 'es-iterator-helpers/Iterator.prototype.toArray';

import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import parsers from '../../__util__/helpers/parsers';
Expand Down Expand Up @@ -42,7 +39,7 @@ const componentsSettings = {
};

// Create basic test cases using all valid role types.
const basicValidityTests = toArray(map(iterFrom(roles.keys()), (role) => {
const basicValidityTests = roles.keys().map((role) => {
const {
requiredProps: requiredPropKeyValues,
} = roles.get(role);
Expand All @@ -52,7 +49,7 @@ const basicValidityTests = toArray(map(iterFrom(roles.keys()), (role) => {
return {
code: `<div role="${role.toLowerCase()}" ${propChain} />`,
};
}));
});

ruleTester.run('role-has-required-aria-props', rule, {
valid: parsers.all([].concat(
Expand Down
17 changes: 6 additions & 11 deletions __tests__/src/rules/role-supports-aria-props-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import {
import { RuleTester } from 'eslint';
import { version as eslintVersion } from 'eslint/package.json';
import semver from 'semver';
import iterFrom from 'es-iterator-helpers/Iterator.from';
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
import map from 'es-iterator-helpers/Iterator.prototype.map';
import toArray from 'es-iterator-helpers/Iterator.prototype.toArray';

import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import parsers from '../../__util__/helpers/parsers';
Expand Down Expand Up @@ -50,27 +46,26 @@ const componentsSettings = {
},
};

const nonAbstractRoles = toArray(filter(iterFrom(roles.keys()), (role) => roles.get(role).abstract === false));
const nonAbstractRoles = roles.keys().filter((role) => roles.get(role).abstract === false);

const createTests = (rolesNames) => rolesNames.reduce((tests, role) => {
const {
props: propKeyValues,
} = roles.get(role);
const validPropsForRole = Object.keys(propKeyValues);
const invalidPropsForRole = filter(
map(iterFrom(aria.keys()), (attribute) => attribute.toLowerCase()),
(attribute) => validPropsForRole.indexOf(attribute) === -1,
);
const invalidPropsForRole = aria.keys()
.map((attribute) => attribute.toLowerCase())
.filter((attribute) => validPropsForRole.indexOf(attribute) === -1);
const normalRole = role.toLowerCase();

return [
tests[0].concat(validPropsForRole.map((prop) => ({
code: `<div role="${normalRole}" ${prop.toLowerCase()} />`,
}))),
tests[1].concat(toArray(map(invalidPropsForRole, (prop) => ({
tests[1].concat(invalidPropsForRole.map((prop) => ({
code: `<div role="${normalRole}" ${prop.toLowerCase()} />`,
errors: [errorMessage(prop.toLowerCase(), normalRole, 'div', false)],
})))),
}))),
];
}, [[], []]);

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"axobject-query": "^4.1.0",
"damerau-levenshtein": "^1.0.8",
"emoji-regex": "^9.2.2",
"es-iterator-helpers": "^1.1.0",
"hasown": "^2.0.2",
"jsx-ast-utils": "^3.3.5",
"language-tags": "^1.0.9",
Expand Down
4 changes: 1 addition & 3 deletions src/rules/aria-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import { dom, roles } from 'aria-query';
import { getLiteralPropValue, propName } from 'jsx-ast-utils';
import iterFrom from 'es-iterator-helpers/Iterator.from';
import filter from 'es-iterator-helpers/Iterator.prototype.filter';

import getElementType from '../util/getElementType';
import { generateObjSchema } from '../util/schemas';
Expand All @@ -31,7 +29,7 @@ const schema = generateObjSchema({
},
});

const validRoles = new Set(filter(iterFrom(roles.keys()), (role) => roles.get(role).abstract === false));
const validRoles = new Set(roles.keys().filter((role) => roles.get(role).abstract === false));

export default {
meta: {
Expand Down
4 changes: 1 addition & 3 deletions src/rules/role-supports-aria-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {
getPropValue,
propName,
} from 'jsx-ast-utils';
import iterFrom from 'es-iterator-helpers/Iterator.from';
import filter from 'es-iterator-helpers/Iterator.prototype.filter';

import { generateObjSchema } from '../util/schemas';
import getElementType from '../util/getElementType';
Expand Down Expand Up @@ -68,7 +66,7 @@ export default {
const {
props: propKeyValues,
} = roles.get(roleValue);
const invalidAriaPropsForRole = new Set(filter(iterFrom(aria.keys()), (attribute) => !(attribute in propKeyValues)));
const invalidAriaPropsForRole = new Set(aria.keys().filter((attribute) => !(attribute in propKeyValues)));

node.attributes.filter((prop) => (
getPropValue(prop) != null // Ignore the attribute if its value is null or undefined.
Expand Down
4 changes: 1 addition & 3 deletions src/util/isAbstractRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {
roles,
} from 'aria-query';
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
import iterFrom from 'es-iterator-helpers/Iterator.from';
import filter from 'es-iterator-helpers/Iterator.prototype.filter';

const abstractRoles = new Set(filter(iterFrom(roles.keys()), (role) => roles.get(role).abstract));
const abstractRoles = new Set(roles.keys().filter((role) => roles.get(role).abstract));

const DOMElements = new Set(dom.keys());

Expand Down
15 changes: 4 additions & 11 deletions src/util/isInteractiveElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import {
} from 'axobject-query';
import includes from 'array-includes';
import flatMap from 'array.prototype.flatmap';
import iterFrom from 'es-iterator-helpers/Iterator.from';
// import iterFlatMap from 'es-iterator-helpers/Iterator.prototype.flatMap';
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
import some from 'es-iterator-helpers/Iterator.prototype.some';

import attributesComparator from './attributesComparator';

Expand Down Expand Up @@ -55,21 +51,18 @@ const interactiveRoles = new Set(roleKeys
'toolbar',
));

// TODO: convert to use iterFlatMap and iterFrom
const interactiveElementRoleSchemas = flatMap(
elementRoleEntries,
([elementSchema, rolesArr]) => (rolesArr.some((role): boolean => interactiveRoles.has(role)) ? [elementSchema] : []),
);

// TODO: convert to use iterFlatMap and iterFrom
const nonInteractiveElementRoleSchemas = flatMap(
elementRoleEntries,
([elementSchema, rolesArr]) => (rolesArr.every((role): boolean => nonInteractiveRoles.has(role)) ? [elementSchema] : []),
);

const interactiveAXObjects = new Set(filter(iterFrom(AXObjects.keys()), (name) => AXObjects.get(name).type === 'widget'));
const interactiveAXObjects = new Set(AXObjects.keys().filter((name) => AXObjects.get(name).type === 'widget'));

// TODO: convert to use iterFlatMap and iterFrom
const interactiveElementAXObjectSchemas = flatMap(
[...elementAXObjects],
([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => interactiveAXObjects.has(role)) ? [elementSchema] : []),
Expand All @@ -85,18 +78,18 @@ function checkIsInteractiveElement(tagName, attributes): boolean {

// Check in elementRoles for inherent interactive role associations for
// this element.
const isInherentInteractiveElement = some(iterFrom(interactiveElementRoleSchemas), elementSchemaMatcher);
const isInherentInteractiveElement = interactiveElementRoleSchemas.some(elementSchemaMatcher);
if (isInherentInteractiveElement) {
return true;
}
// Check in elementRoles for inherent non-interactive role associations for
// this element.
const isInherentNonInteractiveElement = some(iterFrom(nonInteractiveElementRoleSchemas), elementSchemaMatcher);
const isInherentNonInteractiveElement = nonInteractiveElementRoleSchemas.some(elementSchemaMatcher);
if (isInherentNonInteractiveElement) {
return false;
}
// Check in elementAXObjects for AX Tree associations for this element.
const isInteractiveAXElement = some(iterFrom(interactiveElementAXObjectSchemas), elementSchemaMatcher);
const isInteractiveAXElement = interactiveElementAXObjectSchemas.some(elementSchemaMatcher);
if (isInteractiveAXElement) {
return true;
}
Expand Down
15 changes: 4 additions & 11 deletions src/util/isNonInteractiveElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import {
import type { Node } from 'ast-types-flow';
import includes from 'array-includes';
import flatMap from 'array.prototype.flatmap';
import iterFrom from 'es-iterator-helpers/Iterator.from';
// import iterFlatMap from 'es-iterator-helpers/Iterator.prototype.flatMap';
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
import some from 'es-iterator-helpers/Iterator.prototype.some';

import attributesComparator from './attributesComparator';

Expand Down Expand Up @@ -62,21 +58,18 @@ const interactiveRoles = new Set(roleKeys
'toolbar',
));

// TODO: convert to use iterFlatMap and iterFrom
const interactiveElementRoleSchemas = flatMap(
elementRoleEntries,
([elementSchema, rolesArr]) => (rolesArr.some((role): boolean => interactiveRoles.has(role)) ? [elementSchema] : []),
);

// TODO: convert to use iterFlatMap and iterFrom
const nonInteractiveElementRoleSchemas = flatMap(
elementRoleEntries,
([elementSchema, rolesArr]) => (rolesArr.every((role): boolean => nonInteractiveRoles.has(role)) ? [elementSchema] : []),
);

const nonInteractiveAXObjects = new Set(filter(iterFrom(AXObjects.keys()), (name) => includes(['window', 'structure'], AXObjects.get(name).type)));
const nonInteractiveAXObjects = new Set(AXObjects.keys().filter((name) => includes(['window', 'structure'], AXObjects.get(name).type)));

// TODO: convert to use iterFlatMap and iterFrom
const nonInteractiveElementAXObjectSchemas = flatMap(
[...elementAXObjects],
([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => nonInteractiveAXObjects.has(role)) ? [elementSchema] : []),
Expand All @@ -92,18 +85,18 @@ function checkIsNonInteractiveElement(tagName, attributes): boolean {
}
// Check in elementRoles for inherent non-interactive role associations for
// this element.
const isInherentNonInteractiveElement = some(iterFrom(nonInteractiveElementRoleSchemas), elementSchemaMatcher);
const isInherentNonInteractiveElement = nonInteractiveElementRoleSchemas.some(elementSchemaMatcher);
if (isInherentNonInteractiveElement) {
return true;
}
// Check in elementRoles for inherent interactive role associations for
// this element.
const isInherentInteractiveElement = some(iterFrom(interactiveElementRoleSchemas), elementSchemaMatcher);
const isInherentInteractiveElement = interactiveElementRoleSchemas.some(elementSchemaMatcher);
if (isInherentInteractiveElement) {
return false;
}
// Check in elementAXObjects for AX Tree associations for this element.
const isNonInteractiveAXElement = some(iterFrom(nonInteractiveElementAXObjectSchemas), elementSchemaMatcher);
const isNonInteractiveAXElement = nonInteractiveElementAXObjectSchemas.some(elementSchemaMatcher);
if (isNonInteractiveAXElement) {
return true;
}
Expand Down

0 comments on commit 697cc90

Please sign in to comment.