Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slimy-taxes-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-jsx-a11y-x": patch
---

Removes `flatMap` polyfill and uses native functionality instead.
5 changes: 2 additions & 3 deletions __tests__/__util__/helpers/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from 'path';
import semver from 'semver';
import entries from 'object.entries';
import { version } from 'eslint/package.json';
import flatMap from 'array.prototype.flatmap';

let tsParserVersion;
try {
Expand All @@ -26,7 +25,7 @@ function minEcmaVersion(features, parserOptions) {
...[]
.concat(
(parserOptions && parserOptions.ecmaVersion) || [],
flatMap(entries(minEcmaVersionForFeatures), entry => {
entries(minEcmaVersionForFeatures).flatMap(entry => {
const f = entry[0];
const y = entry[1];
return features.has(f) ? y : [];
Expand Down Expand Up @@ -78,7 +77,7 @@ const parsers = {
};
},
all: function all(tests) {
const t = flatMap(tests, test => {
const t = tests.flatMap(test => {
/* eslint no-param-reassign: 0 */
if (typeof test === 'string') {
test = { code: test };
Expand Down
3 changes: 1 addition & 2 deletions __tests__/__util__/ruleOptionsMapperFactory.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @flow */

import entries from 'object.entries';
import flatMap from 'array.prototype.flatmap';
import fromEntries from 'object.fromentries';

type ESLintTestRunnerTestCase = {
Expand Down Expand Up @@ -33,7 +32,7 @@ export default function ruleOptionsMapperFactory(
// Flatten the array of objects in an array of one object.
options: [
fromEntries(
flatMap((options || []).concat(ruleOptions), item => entries(item)),
(options || []).concat(ruleOptions).flatMap(item => entries(item)),
),
],
parserOptions,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
},
"dependencies": {
"aria-query": "^5.3.2",
"array.prototype.flatmap": "^1.3.2",
"ast-types-flow": "^0.0.8",
"axe-core": "^4.10.2",
"axobject-query": "^4.1.0",
Expand Down
4 changes: 1 addition & 3 deletions src/rules/alt-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// ----------------------------------------------------------------------------

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

import { generateObjSchema, arraySchema } from '../util/schemas';
import getElementType from '../util/getElementType';
Expand Down Expand Up @@ -218,8 +217,7 @@ export default {
// Elements to validate for alt text.
const elementOptions = options.elements || DEFAULT_ELEMENTS;
// Get custom components for just the elements that will be tested.
const customComponents = flatMap(
elementOptions,
const customComponents = elementOptions.flatMap(
element => options[element],
);
const typesToValidate = new Set(
Expand Down
3 changes: 1 addition & 2 deletions src/rules/media-has-caption.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

import type {
ESLintConfig,
Expand All @@ -34,7 +33,7 @@ const schema = generateObjSchema({
const isMediaType = (context, type) => {
const options = context.options[0] || {};
return MEDIA_TYPES.concat(
flatMap(MEDIA_TYPES, mediaType => options[mediaType]),
MEDIA_TYPES.flatMap(mediaType => options[mediaType]),
).some(typeToCheck => typeToCheck === type);
};

Expand Down
10 changes: 3 additions & 7 deletions src/util/isInteractiveElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { dom, elementRoles, roles } from 'aria-query';
import type { Node } from 'ast-types-flow';
import { AXObjects, elementAXObjects } from 'axobject-query';
import flatMap from 'array.prototype.flatmap';

import attributesComparator from './attributesComparator';

Expand Down Expand Up @@ -47,16 +46,14 @@ const interactiveRoles = new Set(
),
);

const interactiveElementRoleSchemas = flatMap(
elementRoleEntries,
const interactiveElementRoleSchemas = elementRoleEntries.flatMap(
([elementSchema, rolesArr]) =>
rolesArr.some((role): boolean => interactiveRoles.has(role))
? [elementSchema]
: [],
);

const nonInteractiveElementRoleSchemas = flatMap(
elementRoleEntries,
const nonInteractiveElementRoleSchemas = elementRoleEntries.flatMap(
([elementSchema, rolesArr]) =>
rolesArr.every((role): boolean => nonInteractiveRoles.has(role))
? [elementSchema]
Expand All @@ -67,8 +64,7 @@ const interactiveAXObjects = new Set(
AXObjects.keys().filter(name => AXObjects.get(name).type === 'widget'),
);

const interactiveElementAXObjectSchemas = flatMap(
[...elementAXObjects],
const interactiveElementAXObjectSchemas = [...elementAXObjects].flatMap(
([elementSchema, AXObjectsArr]) =>
AXObjectsArr.every((role): boolean => interactiveAXObjects.has(role))
? [elementSchema]
Expand Down
3 changes: 1 addition & 2 deletions src/util/isInteractiveRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { roles as rolesMap } from 'aria-query';
import type { Node } from 'ast-types-flow';
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
import flatMap from 'array.prototype.flatmap';

const roles = rolesMap.keys();
const interactiveRoles = roles.filter(
Expand Down Expand Up @@ -40,7 +39,7 @@ const isInteractiveRole = (

let isInteractive = false;
const normalizedValues = String(value).toLowerCase().split(' ');
const validRoles = flatMap(normalizedValues, (name: string) =>
const validRoles = normalizedValues.flatMap((name: string) =>
roles.includes(name) ? [name] : [],
);
if (validRoles.length > 0) {
Expand Down
10 changes: 3 additions & 7 deletions src/util/isNonInteractiveElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { dom, elementRoles, roles } from 'aria-query';
import { AXObjects, elementAXObjects } from 'axobject-query';
import type { Node } from 'ast-types-flow';
import flatMap from 'array.prototype.flatmap';

import attributesComparator from './attributesComparator';

Expand Down Expand Up @@ -54,16 +53,14 @@ const interactiveRoles = new Set(
),
);

const interactiveElementRoleSchemas = flatMap(
elementRoleEntries,
const interactiveElementRoleSchemas = elementRoleEntries.flatMap(
([elementSchema, rolesArr]) =>
rolesArr.some((role): boolean => interactiveRoles.has(role))
? [elementSchema]
: [],
);

const nonInteractiveElementRoleSchemas = flatMap(
elementRoleEntries,
const nonInteractiveElementRoleSchemas = elementRoleEntries.flatMap(
([elementSchema, rolesArr]) =>
rolesArr.every((role): boolean => nonInteractiveRoles.has(role))
? [elementSchema]
Expand All @@ -76,8 +73,7 @@ const nonInteractiveAXObjects = new Set(
),
);

const nonInteractiveElementAXObjectSchemas = flatMap(
[...elementAXObjects],
const nonInteractiveElementAXObjectSchemas = [...elementAXObjects].flatMap(
([elementSchema, AXObjectsArr]) =>
AXObjectsArr.every((role): boolean => nonInteractiveAXObjects.has(role))
? [elementSchema]
Expand Down
3 changes: 1 addition & 2 deletions src/util/isNonInteractiveRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { dom, roles as rolesMap } from 'aria-query';
import type { Node } from 'ast-types-flow';
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
import flatMap from 'array.prototype.flatmap';

const nonInteractiveRoles = rolesMap
.keys()
Expand Down Expand Up @@ -47,7 +46,7 @@ const isNonInteractiveRole = (

let isNonInteractive = false;
const normalizedValues = String(role).toLowerCase().split(' ');
const validRoles = flatMap(normalizedValues, (name: string) =>
const validRoles = normalizedValues.flatMap((name: string) =>
rolesMap.has(name) ? [name] : [],
);
if (validRoles.length > 0) {
Expand Down
13 changes: 0 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2673,18 +2673,6 @@ __metadata:
languageName: node
linkType: hard

"array.prototype.flatmap@npm:^1.3.2":
version: 1.3.3
resolution: "array.prototype.flatmap@npm:1.3.3"
dependencies:
call-bind: "npm:^1.0.8"
define-properties: "npm:^1.2.1"
es-abstract: "npm:^1.23.5"
es-shim-unscopables: "npm:^1.0.2"
checksum: 10c0/ba899ea22b9dc9bf276e773e98ac84638ed5e0236de06f13d63a90b18ca9e0ec7c97d622d899796e3773930b946cd2413d098656c0c5d8cc58c6f25c21e6bd54
languageName: node
linkType: hard

"arraybuffer.prototype.slice@npm:^1.0.4":
version: 1.0.4
resolution: "arraybuffer.prototype.slice@npm:1.0.4"
Expand Down Expand Up @@ -3808,7 +3796,6 @@ __metadata:
"@eslint/eslintrc": "npm:^3.3.1"
"@eslint/js": "npm:^9.26.0"
aria-query: "npm:^5.3.2"
array.prototype.flatmap: "npm:^1.3.2"
ast-types-flow: "npm:^0.0.8"
auto-changelog: "npm:^2.5.0"
axe-core: "npm:^4.10.2"
Expand Down
Loading