Skip to content

Commit

Permalink
[Refactor] avoid spreading things that are already arrays
Browse files Browse the repository at this point in the history
Co-authored-by: v1rtl <[email protected]>
Co-authored-by: Michaël De Boey <[email protected]>
  • Loading branch information
2 people authored and ljharb committed Oct 25, 2024
1 parent fa9845d commit d15d3ab
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions __mocks__/genInteractives.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import JSXElementMock from './JSXElementMock';
import type { JSXAttributeMockType } from './JSXAttributeMock';
import type { JSXElementMockType } from './JSXElementMock';

const domElements = [...dom.keys()];
const roleNames = [...roles.keys()];
const domElements = dom.keys();
const roleNames = roles.keys();

const interactiveElementsMap = {
a: [{ prop: 'href', value: '#' }],
Expand Down
2 changes: 1 addition & 1 deletion __tests__/src/rules/aria-props-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import getSuggestion from '../../../src/util/getSuggestion';
// -----------------------------------------------------------------------------

const ruleTester = new RuleTester();
const ariaAttributes = [...aria.keys()];
const ariaAttributes = aria.keys();

const errorMessage = (name) => {
const suggestions = getSuggestion(name, ariaAttributes);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/src/rules/aria-role-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const errorMessage = {
type: 'JSXAttribute',
};

const roleKeys = [...roles.keys()];
const roleKeys = roles.keys();

const validRoles = roleKeys.filter((role) => roles.get(role).abstract === false);
const invalidRoles = roleKeys.filter((role) => roles.get(role).abstract === true);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/src/rules/aria-unsupported-elements-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Try removing the prop '${invalidProp}'.`,
type: 'JSXOpeningElement',
});

const domElements = [...dom.keys()];
const domElements = dom.keys();
// Generate valid test cases
const roleValidityTests = domElements.map((element) => {
const isReserved = dom.get(element).reserved || false;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/aria-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { propName } from 'jsx-ast-utils';
import { generateObjSchema } from '../util/schemas';
import getSuggestion from '../util/getSuggestion';

const ariaAttributes = [...aria.keys()];
const ariaAttributes = aria.keys();

const errorMessage = (name) => {
const suggestions = getSuggestion(name, ariaAttributes);
Expand Down
4 changes: 2 additions & 2 deletions src/rules/aria-unsupported-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const errorMessage = (invalidProp) => (
Try removing the prop '${invalidProp}'.`
);

const invalidAttributes = new Set(aria.keys().concat('role'));

const schema = generateObjSchema();

export default {
Expand All @@ -47,8 +49,6 @@ export default {
return;
}

const invalidAttributes = new Set([...aria.keys(), 'role']);

node.attributes.forEach((prop) => {
if (prop.type === 'JSXSpreadAttribute') {
return;
Expand Down
4 changes: 3 additions & 1 deletion src/rules/role-has-required-aria-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const errorMessage = (role, requiredProps) => (

const schema = generateObjSchema();

const roleKeys = roles.keys();

export default {
meta: {
docs: {
Expand Down Expand Up @@ -60,7 +62,7 @@ export default {

const normalizedValues = String(roleAttrValue).toLowerCase().split(' ');
const validRoles = normalizedValues
.filter((val) => [...roles.keys()].indexOf(val) > -1);
.filter((val) => roleKeys.indexOf(val) > -1);

// Check semantic DOM elements
// For example, <input type="checkbox" role="switch" />
Expand Down
2 changes: 1 addition & 1 deletion src/util/isInteractiveElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import flatMap from 'array.prototype.flatmap';

import attributesComparator from './attributesComparator';

const roleKeys = [...roles.keys()];
const roleKeys = roles.keys();
const elementRoleEntries = [...elementRoles];

const nonInteractiveRoles = new Set(roleKeys
Expand Down
2 changes: 1 addition & 1 deletion src/util/isInteractiveRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
import includes from 'array-includes';
import flatMap from 'array.prototype.flatmap';

const roles = [...rolesMap.keys()];
const roles = rolesMap.keys();
const interactiveRoles = roles.filter((name) => (
!rolesMap.get(name).abstract
&& rolesMap.get(name).superClass.some((klasses) => includes(klasses, 'widget'))
Expand Down
2 changes: 1 addition & 1 deletion src/util/isNonInteractiveElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import flatMap from 'array.prototype.flatmap';

import attributesComparator from './attributesComparator';

const roleKeys = [...roles.keys()];
const roleKeys = roles.keys();
const elementRoleEntries = [...elementRoles];

const nonInteractiveRoles = new Set(roleKeys
Expand Down
2 changes: 1 addition & 1 deletion src/util/isNonInteractiveRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
import includes from 'array-includes';
import flatMap from 'array.prototype.flatmap';

const nonInteractiveRoles = [...rolesMap.keys()].filter((name) => (
const nonInteractiveRoles = rolesMap.keys().filter((name) => (
!rolesMap.get(name).abstract
&& !rolesMap.get(name).superClass.some((klasses) => includes(klasses, 'widget'))
));
Expand Down

0 comments on commit d15d3ab

Please sign in to comment.