Skip to content

Commit d15d3ab

Browse files
talentlessguyMichaelDeBoey
authored andcommittedOct 25, 2024··
[Refactor] avoid spreading things that are already arrays
Co-authored-by: v1rtl <hi@v1rtl.site> Co-authored-by: Michaël De Boey <info@michaeldeboey.be>
1 parent fa9845d commit d15d3ab

11 files changed

+15
-13
lines changed
 

‎__mocks__/genInteractives.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import JSXElementMock from './JSXElementMock';
1212
import type { JSXAttributeMockType } from './JSXAttributeMock';
1313
import type { JSXElementMockType } from './JSXElementMock';
1414

15-
const domElements = [...dom.keys()];
16-
const roleNames = [...roles.keys()];
15+
const domElements = dom.keys();
16+
const roleNames = roles.keys();
1717

1818
const interactiveElementsMap = {
1919
a: [{ prop: 'href', value: '#' }],

‎__tests__/src/rules/aria-props-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import getSuggestion from '../../../src/util/getSuggestion';
1919
// -----------------------------------------------------------------------------
2020

2121
const ruleTester = new RuleTester();
22-
const ariaAttributes = [...aria.keys()];
22+
const ariaAttributes = aria.keys();
2323

2424
const errorMessage = (name) => {
2525
const suggestions = getSuggestion(name, ariaAttributes);

‎__tests__/src/rules/aria-role-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const errorMessage = {
2424
type: 'JSXAttribute',
2525
};
2626

27-
const roleKeys = [...roles.keys()];
27+
const roleKeys = roles.keys();
2828

2929
const validRoles = roleKeys.filter((role) => roles.get(role).abstract === false);
3030
const invalidRoles = roleKeys.filter((role) => roles.get(role).abstract === true);

‎__tests__/src/rules/aria-unsupported-elements-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Try removing the prop '${invalidProp}'.`,
2626
type: 'JSXOpeningElement',
2727
});
2828

29-
const domElements = [...dom.keys()];
29+
const domElements = dom.keys();
3030
// Generate valid test cases
3131
const roleValidityTests = domElements.map((element) => {
3232
const isReserved = dom.get(element).reserved || false;

‎src/rules/aria-props.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { propName } from 'jsx-ast-utils';
1212
import { generateObjSchema } from '../util/schemas';
1313
import getSuggestion from '../util/getSuggestion';
1414

15-
const ariaAttributes = [...aria.keys()];
15+
const ariaAttributes = aria.keys();
1616

1717
const errorMessage = (name) => {
1818
const suggestions = getSuggestion(name, ariaAttributes);

‎src/rules/aria-unsupported-elements.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const errorMessage = (invalidProp) => (
2121
Try removing the prop '${invalidProp}'.`
2222
);
2323

24+
const invalidAttributes = new Set(aria.keys().concat('role'));
25+
2426
const schema = generateObjSchema();
2527

2628
export default {
@@ -47,8 +49,6 @@ export default {
4749
return;
4850
}
4951

50-
const invalidAttributes = new Set([...aria.keys(), 'role']);
51-
5252
node.attributes.forEach((prop) => {
5353
if (prop.type === 'JSXSpreadAttribute') {
5454
return;

‎src/rules/role-has-required-aria-props.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const errorMessage = (role, requiredProps) => (
2424

2525
const schema = generateObjSchema();
2626

27+
const roleKeys = roles.keys();
28+
2729
export default {
2830
meta: {
2931
docs: {
@@ -60,7 +62,7 @@ export default {
6062

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

6567
// Check semantic DOM elements
6668
// For example, <input type="checkbox" role="switch" />

‎src/util/isInteractiveElement.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import flatMap from 'array.prototype.flatmap';
1616

1717
import attributesComparator from './attributesComparator';
1818

19-
const roleKeys = [...roles.keys()];
19+
const roleKeys = roles.keys();
2020
const elementRoleEntries = [...elementRoles];
2121

2222
const nonInteractiveRoles = new Set(roleKeys

‎src/util/isInteractiveRole.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
55
import includes from 'array-includes';
66
import flatMap from 'array.prototype.flatmap';
77

8-
const roles = [...rolesMap.keys()];
8+
const roles = rolesMap.keys();
99
const interactiveRoles = roles.filter((name) => (
1010
!rolesMap.get(name).abstract
1111
&& rolesMap.get(name).superClass.some((klasses) => includes(klasses, 'widget'))

‎src/util/isNonInteractiveElement.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import flatMap from 'array.prototype.flatmap';
1717

1818
import attributesComparator from './attributesComparator';
1919

20-
const roleKeys = [...roles.keys()];
20+
const roleKeys = roles.keys();
2121
const elementRoleEntries = [...elementRoles];
2222

2323
const nonInteractiveRoles = new Set(roleKeys

‎src/util/isNonInteractiveRole.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
1111
import includes from 'array-includes';
1212
import flatMap from 'array.prototype.flatmap';
1313

14-
const nonInteractiveRoles = [...rolesMap.keys()].filter((name) => (
14+
const nonInteractiveRoles = rolesMap.keys().filter((name) => (
1515
!rolesMap.get(name).abstract
1616
&& !rolesMap.get(name).superClass.some((klasses) => includes(klasses, 'widget'))
1717
));

0 commit comments

Comments
 (0)
Please sign in to comment.