Skip to content

Commit d4af7b1

Browse files
talentlessguyljharb
authored andcommitted
[Refactor] remove array.prototype.flatmap
1 parent 2d566d8 commit d4af7b1

File tree

9 files changed

+14
-50
lines changed

9 files changed

+14
-50
lines changed

__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 {
@@ -23,7 +22,7 @@ function minEcmaVersion(features, parserOptions) {
2322
const result = Math.max(
2423
...[].concat(
2524
(parserOptions && parserOptions.ecmaVersion) || [],
26-
flatMap(entries(minEcmaVersionForFeatures), (entry) => {
25+
entries(minEcmaVersionForFeatures).flatMap((entry) => {
2726
const f = entry[0];
2827
const y = entry[1];
2928
return features.has(f) ? y : [];
@@ -69,7 +68,7 @@ const parsers = {
6968
};
7069
},
7170
all: function all(tests) {
72-
const t = flatMap(tests, (test) => {
71+
const t = tests.flatMap((test) => {
7372
/* eslint no-param-reassign: 0 */
7473
if (typeof test === 'string') {
7574
test = { code: test };

__tests__/__util__/ruleOptionsMapperFactory.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* @flow
33
*/
44

5-
import flatMap from 'array.prototype.flatmap';
6-
75
const { fromEntries, entries } = Object;
86

97
type ESLintTestRunnerTestCase = {
@@ -25,7 +23,7 @@ export default function ruleOptionsMapperFactory(ruleOptions: Array<mixed> = [])
2523
code,
2624
errors,
2725
// Flatten the array of objects in an array of one object.
28-
options: [fromEntries(flatMap((options || []).concat(ruleOptions), (item) => entries(item)))],
26+
options: [fromEntries((options || []).concat(ruleOptions).flatMap((item) => entries(item)))],
2927
parserOptions,
3028
settings,
3129
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
"license": "MIT",
7777
"dependencies": {
7878
"aria-query": "^5.3.2",
79-
"array.prototype.flatmap": "^1.3.2",
8079
"ast-types-flow": "^0.0.8",
8180
"axe-core": "^4.10.0",
8281
"axobject-query": "^4.1.0",

src/rules/alt-text.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
getPropValue,
1313
getLiteralPropValue,
1414
} from 'jsx-ast-utils';
15-
import flatMap from 'array.prototype.flatmap';
1615

1716
import { generateObjSchema, arraySchema } from '../util/schemas';
1817
import getElementType from '../util/getElementType';
@@ -206,10 +205,8 @@ export default {
206205
// Elements to validate for alt text.
207206
const elementOptions = options.elements || DEFAULT_ELEMENTS;
208207
// Get custom components for just the elements that will be tested.
209-
const customComponents = flatMap(
210-
elementOptions,
211-
(element) => options[element],
212-
);
208+
const customComponents = elementOptions.flatMap((element) => options[element]);
209+
213210
const typesToValidate = new Set(
214211
[].concat(
215212
customComponents,

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 { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
1615
import { generateObjSchema, arraySchema } from '../util/schemas';
@@ -29,7 +28,7 @@ const schema = generateObjSchema({
2928
const isMediaType = (context, type) => {
3029
const options = context.options[0] || {};
3130
return MEDIA_TYPES
32-
.concat(flatMap(MEDIA_TYPES, (mediaType) => options[mediaType]))
31+
.concat(MEDIA_TYPES.flatMap((mediaType) => options[mediaType]))
3332
.some((typeToCheck) => typeToCheck === type);
3433
};
3534

src/util/isInteractiveElement.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
AXObjects,
1212
elementAXObjects,
1313
} from 'axobject-query';
14-
import flatMap from 'array.prototype.flatmap';
1514
import iterFrom from 'es-iterator-helpers/Iterator.from';
1615
// import iterFlatMap from 'es-iterator-helpers/Iterator.prototype.flatMap';
1716
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
@@ -55,24 +54,15 @@ const interactiveRoles = new Set(roleKeys
5554
));
5655

5756
// TODO: convert to use iterFlatMap and iterFrom
58-
const interactiveElementRoleSchemas = flatMap(
59-
elementRoleEntries,
60-
([elementSchema, rolesArr]) => (rolesArr.some((role): boolean => interactiveRoles.has(role)) ? [elementSchema] : []),
61-
);
57+
const interactiveElementRoleSchemas = elementRoleEntries.flatMap(([elementSchema, rolesArr]) => (rolesArr.some((role): boolean => interactiveRoles.has(role)) ? [elementSchema] : []));
6258

6359
// TODO: convert to use iterFlatMap and iterFrom
64-
const nonInteractiveElementRoleSchemas = flatMap(
65-
elementRoleEntries,
66-
([elementSchema, rolesArr]) => (rolesArr.every((role): boolean => nonInteractiveRoles.has(role)) ? [elementSchema] : []),
67-
);
60+
const nonInteractiveElementRoleSchemas = elementRoleEntries.flatMap(([elementSchema, rolesArr]) => (rolesArr.every((role): boolean => nonInteractiveRoles.has(role)) ? [elementSchema] : []));
6861

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

7164
// TODO: convert to use iterFlatMap and iterFrom
72-
const interactiveElementAXObjectSchemas = flatMap(
73-
[...elementAXObjects],
74-
([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => interactiveAXObjects.has(role)) ? [elementSchema] : []),
75-
);
65+
const interactiveElementAXObjectSchemas = [...elementAXObjects].flatMap(([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => interactiveAXObjects.has(role)) ? [elementSchema] : []));
7666

7767
function checkIsInteractiveElement(tagName, attributes): boolean {
7868
function elementSchemaMatcher(elementSchema) {

src/util/isInteractiveRole.js

Lines changed: 1 addition & 5 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((name) => (
@@ -39,10 +38,7 @@ const isInteractiveRole = (
3938

4039
let isInteractive = false;
4140
const normalizedValues = String(value).toLowerCase().split(' ');
42-
const validRoles = flatMap(
43-
normalizedValues,
44-
(name: string) => (roles.includes(name) ? [name] : []),
45-
);
41+
const validRoles = normalizedValues.flatMap((name) => (roles.includes(name) ? [name] : []));
4642
if (validRoles.length > 0) {
4743
// The first role value is a series takes precedence.
4844
isInteractive = interactiveRoles.includes(validRoles[0]);

src/util/isNonInteractiveElement.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
elementAXObjects,
1313
} from 'axobject-query';
1414
import type { Node } from 'ast-types-flow';
15-
import flatMap from 'array.prototype.flatmap';
1615
import iterFrom from 'es-iterator-helpers/Iterator.from';
1716
// import iterFlatMap from 'es-iterator-helpers/Iterator.prototype.flatMap';
1817
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
@@ -62,24 +61,15 @@ const interactiveRoles = new Set(roleKeys
6261
));
6362

6463
// TODO: convert to use iterFlatMap and iterFrom
65-
const interactiveElementRoleSchemas = flatMap(
66-
elementRoleEntries,
67-
([elementSchema, rolesArr]) => (rolesArr.some((role): boolean => interactiveRoles.has(role)) ? [elementSchema] : []),
68-
);
64+
const interactiveElementRoleSchemas = elementRoleEntries.flatMap(([elementSchema, rolesArr]) => (rolesArr.some((role): boolean => interactiveRoles.has(role)) ? [elementSchema] : []));
6965

7066
// TODO: convert to use iterFlatMap and iterFrom
71-
const nonInteractiveElementRoleSchemas = flatMap(
72-
elementRoleEntries,
73-
([elementSchema, rolesArr]) => (rolesArr.every((role): boolean => nonInteractiveRoles.has(role)) ? [elementSchema] : []),
74-
);
67+
const nonInteractiveElementRoleSchemas = elementRoleEntries.flatMap(([elementSchema, rolesArr]) => (rolesArr.every((role): boolean => nonInteractiveRoles.has(role)) ? [elementSchema] : []));
7568

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

7871
// TODO: convert to use iterFlatMap and iterFrom
79-
const nonInteractiveElementAXObjectSchemas = flatMap(
80-
[...elementAXObjects],
81-
([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => nonInteractiveAXObjects.has(role)) ? [elementSchema] : []),
82-
);
72+
const nonInteractiveElementAXObjectSchemas = [...elementAXObjects].flatMap(([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => nonInteractiveAXObjects.has(role)) ? [elementSchema] : []));
8373

8474
function checkIsNonInteractiveElement(tagName, attributes): boolean {
8575
function elementSchemaMatcher(elementSchema) {

src/util/isNonInteractiveRole.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
} from 'aria-query';
99
import type { Node } from 'ast-types-flow';
1010
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
11-
import flatMap from 'array.prototype.flatmap';
1211

1312
const nonInteractiveRoles = [...rolesMap.keys()].filter((name) => (
1413
!rolesMap.get(name).abstract
@@ -47,10 +46,7 @@ const isNonInteractiveRole = (
4746

4847
let isNonInteractive = false;
4948
const normalizedValues = String(role).toLowerCase().split(' ');
50-
const validRoles = flatMap(
51-
normalizedValues,
52-
(name: string) => (rolesMap.has(name) ? [name] : []),
53-
);
49+
const validRoles = normalizedValues.flatMap((name: string) => (rolesMap.has(name) ? [name] : []));
5450
if (validRoles.length > 0) {
5551
// The first role value is a series takes precedence.
5652
isNonInteractive = nonInteractiveRoles.includes(validRoles[0]);

0 commit comments

Comments
 (0)