Skip to content

Commit 2627d60

Browse files
authored
chore: remove flatMap polyfill (#18)
Uses native functionality instead. Part of #16.
1 parent fc498c5 commit 2627d60

File tree

11 files changed

+18
-42
lines changed

11 files changed

+18
-42
lines changed

.changeset/slimy-taxes-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-jsx-a11y-x": patch
3+
---
4+
5+
Removes `flatMap` polyfill and uses native functionality instead.

__tests__/__util__/helpers/parsers.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import path from 'path';
22
import semver from 'semver';
33
import entries from 'object.entries';
44
import { version } from 'eslint/package.json';
5-
import flatMap from 'array.prototype.flatmap';
65

76
let tsParserVersion;
87
try {
@@ -26,7 +25,7 @@ function minEcmaVersion(features, parserOptions) {
2625
...[]
2726
.concat(
2827
(parserOptions && parserOptions.ecmaVersion) || [],
29-
flatMap(entries(minEcmaVersionForFeatures), entry => {
28+
entries(minEcmaVersionForFeatures).flatMap(entry => {
3029
const f = entry[0];
3130
const y = entry[1];
3231
return features.has(f) ? y : [];
@@ -78,7 +77,7 @@ const parsers = {
7877
};
7978
},
8079
all: function all(tests) {
81-
const t = flatMap(tests, test => {
80+
const t = tests.flatMap(test => {
8281
/* eslint no-param-reassign: 0 */
8382
if (typeof test === 'string') {
8483
test = { code: test };

__tests__/__util__/ruleOptionsMapperFactory.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/** @flow */
22

33
import entries from 'object.entries';
4-
import flatMap from 'array.prototype.flatmap';
54
import fromEntries from 'object.fromentries';
65

76
type ESLintTestRunnerTestCase = {
@@ -33,7 +32,7 @@ export default function ruleOptionsMapperFactory(
3332
// Flatten the array of objects in an array of one object.
3433
options: [
3534
fromEntries(
36-
flatMap((options || []).concat(ruleOptions), item => entries(item)),
35+
(options || []).concat(ruleOptions).flatMap(item => entries(item)),
3736
),
3837
],
3938
parserOptions,

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
},
5050
"dependencies": {
5151
"aria-query": "^5.3.2",
52-
"array.prototype.flatmap": "^1.3.2",
5352
"ast-types-flow": "^0.0.8",
5453
"axe-core": "^4.10.2",
5554
"axobject-query": "^4.1.0",

src/rules/alt-text.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// ----------------------------------------------------------------------------
99

1010
import { getProp, getPropValue, getLiteralPropValue } from 'jsx-ast-utils';
11-
import flatMap from 'array.prototype.flatmap';
1211

1312
import { generateObjSchema, arraySchema } from '../util/schemas';
1413
import getElementType from '../util/getElementType';
@@ -218,8 +217,7 @@ export default {
218217
// Elements to validate for alt text.
219218
const elementOptions = options.elements || DEFAULT_ELEMENTS;
220219
// Get custom components for just the elements that will be tested.
221-
const customComponents = flatMap(
222-
elementOptions,
220+
const customComponents = elementOptions.flatMap(
223221
element => options[element],
224222
);
225223
const typesToValidate = new Set(

src/rules/media-has-caption.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import type { JSXElement, JSXOpeningElement, Node } from 'ast-types-flow';
1212
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
13-
import flatMap from 'array.prototype.flatmap';
1413

1514
import type {
1615
ESLintConfig,
@@ -34,7 +33,7 @@ const schema = generateObjSchema({
3433
const isMediaType = (context, type) => {
3534
const options = context.options[0] || {};
3635
return MEDIA_TYPES.concat(
37-
flatMap(MEDIA_TYPES, mediaType => options[mediaType]),
36+
MEDIA_TYPES.flatMap(mediaType => options[mediaType]),
3837
).some(typeToCheck => typeToCheck === type);
3938
};
4039

src/util/isInteractiveElement.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { dom, elementRoles, roles } from 'aria-query';
33
import type { Node } from 'ast-types-flow';
44
import { AXObjects, elementAXObjects } from 'axobject-query';
5-
import flatMap from 'array.prototype.flatmap';
65

76
import attributesComparator from './attributesComparator';
87

@@ -47,16 +46,14 @@ const interactiveRoles = new Set(
4746
),
4847
);
4948

50-
const interactiveElementRoleSchemas = flatMap(
51-
elementRoleEntries,
49+
const interactiveElementRoleSchemas = elementRoleEntries.flatMap(
5250
([elementSchema, rolesArr]) =>
5351
rolesArr.some((role): boolean => interactiveRoles.has(role))
5452
? [elementSchema]
5553
: [],
5654
);
5755

58-
const nonInteractiveElementRoleSchemas = flatMap(
59-
elementRoleEntries,
56+
const nonInteractiveElementRoleSchemas = elementRoleEntries.flatMap(
6057
([elementSchema, rolesArr]) =>
6158
rolesArr.every((role): boolean => nonInteractiveRoles.has(role))
6259
? [elementSchema]
@@ -67,8 +64,7 @@ const interactiveAXObjects = new Set(
6764
AXObjects.keys().filter(name => AXObjects.get(name).type === 'widget'),
6865
);
6966

70-
const interactiveElementAXObjectSchemas = flatMap(
71-
[...elementAXObjects],
67+
const interactiveElementAXObjectSchemas = [...elementAXObjects].flatMap(
7268
([elementSchema, AXObjectsArr]) =>
7369
AXObjectsArr.every((role): boolean => interactiveAXObjects.has(role))
7470
? [elementSchema]

src/util/isInteractiveRole.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { roles as rolesMap } from 'aria-query';
33
import type { Node } from 'ast-types-flow';
44
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
5-
import flatMap from 'array.prototype.flatmap';
65

76
const roles = rolesMap.keys();
87
const interactiveRoles = roles.filter(
@@ -40,7 +39,7 @@ const isInteractiveRole = (
4039

4140
let isInteractive = false;
4241
const normalizedValues = String(value).toLowerCase().split(' ');
43-
const validRoles = flatMap(normalizedValues, (name: string) =>
42+
const validRoles = normalizedValues.flatMap((name: string) =>
4443
roles.includes(name) ? [name] : [],
4544
);
4645
if (validRoles.length > 0) {

src/util/isNonInteractiveElement.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { dom, elementRoles, roles } from 'aria-query';
44
import { AXObjects, elementAXObjects } from 'axobject-query';
55
import type { Node } from 'ast-types-flow';
6-
import flatMap from 'array.prototype.flatmap';
76

87
import attributesComparator from './attributesComparator';
98

@@ -54,16 +53,14 @@ const interactiveRoles = new Set(
5453
),
5554
);
5655

57-
const interactiveElementRoleSchemas = flatMap(
58-
elementRoleEntries,
56+
const interactiveElementRoleSchemas = elementRoleEntries.flatMap(
5957
([elementSchema, rolesArr]) =>
6058
rolesArr.some((role): boolean => interactiveRoles.has(role))
6159
? [elementSchema]
6260
: [],
6361
);
6462

65-
const nonInteractiveElementRoleSchemas = flatMap(
66-
elementRoleEntries,
63+
const nonInteractiveElementRoleSchemas = elementRoleEntries.flatMap(
6764
([elementSchema, rolesArr]) =>
6865
rolesArr.every((role): boolean => nonInteractiveRoles.has(role))
6966
? [elementSchema]
@@ -76,8 +73,7 @@ const nonInteractiveAXObjects = new Set(
7673
),
7774
);
7875

79-
const nonInteractiveElementAXObjectSchemas = flatMap(
80-
[...elementAXObjects],
76+
const nonInteractiveElementAXObjectSchemas = [...elementAXObjects].flatMap(
8177
([elementSchema, AXObjectsArr]) =>
8278
AXObjectsArr.every((role): boolean => nonInteractiveAXObjects.has(role))
8379
? [elementSchema]

src/util/isNonInteractiveRole.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { dom, roles as rolesMap } from 'aria-query';
44
import type { Node } from 'ast-types-flow';
55
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
6-
import flatMap from 'array.prototype.flatmap';
76

87
const nonInteractiveRoles = rolesMap
98
.keys()
@@ -47,7 +46,7 @@ const isNonInteractiveRole = (
4746

4847
let isNonInteractive = false;
4948
const normalizedValues = String(role).toLowerCase().split(' ');
50-
const validRoles = flatMap(normalizedValues, (name: string) =>
49+
const validRoles = normalizedValues.flatMap((name: string) =>
5150
rolesMap.has(name) ? [name] : [],
5251
);
5352
if (validRoles.length > 0) {

0 commit comments

Comments
 (0)