Skip to content

Commit fc498c5

Browse files
authored
chore: remove array-includes (#17)
Removes `array-includes` and uses native functionality.
1 parent e911b81 commit fc498c5

19 files changed

+39
-56
lines changed

.changeset/green-pears-clean.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 `array-includes` and uses the built-in `Array.prototype.includes` method instead.

__mocks__/genInteractives.js

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

33
import { dom, roles } from 'aria-query';
4-
import includes from 'array-includes';
54
import fromEntries from 'object.fromentries';
65

76
import JSXAttributeMock from './JSXAttributeMock';
@@ -141,16 +140,16 @@ const interactiveRoles = []
141140
.filter(
142141
role =>
143142
!roles.get(role).abstract &&
144-
roles.get(role).superClass.some(klasses => includes(klasses, 'widget')),
143+
roles.get(role).superClass.some(klasses => klasses.includes('widget')),
145144
);
146145

147146
const nonInteractiveRoles = roleNames.filter(
148147
role =>
149148
!roles.get(role).abstract &&
150-
!roles.get(role).superClass.some(klasses => includes(klasses, 'widget')) &&
149+
!roles.get(role).superClass.some(klasses => klasses.includes('widget')) &&
151150
// 'toolbar' does not descend from widget, but it does support
152151
// aria-activedescendant, thus in practice we treat it as a widget.
153-
!includes(['toolbar'], role),
152+
!['toolbar'].includes(role),
154153
);
155154

156155
export function genElementSymbol(openingElement: Object): string {

__tests__/src/rules/interactive-supports-focus-test.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// Requirements
88
// -----------------------------------------------------------------------------
99

10-
import includes from 'array-includes';
1110
import { RuleTester } from 'eslint';
1211
import { eventHandlers, eventHandlersByType } from 'jsx-ast-utils';
1312
import { configs } from '../../../src/index';
@@ -270,15 +269,13 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
270269
...passReducer(
271270
interactiveRoles,
272271
eventHandlers.filter(
273-
handler => !includes(triggeringHandlers, handler),
272+
handler => !triggeringHandlers.includes(handler),
274273
),
275274
codeTemplate,
276275
),
277276
...passReducer(
278-
interactiveRoles.filter(role => !includes(recommendedRoles, role)),
279-
eventHandlers.filter(handler =>
280-
includes(triggeringHandlers, handler),
281-
),
277+
interactiveRoles.filter(role => !recommendedRoles.includes(role)),
278+
eventHandlers.filter(handler => triggeringHandlers.includes(handler)),
282279
tabindexTemplate,
283280
),
284281
),
@@ -291,7 +288,7 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
291288
...neverValid,
292289
...failReducer(recommendedRoles, triggeringHandlers, tabbableTemplate),
293290
...failReducer(
294-
interactiveRoles.filter(role => !includes(recommendedRoles, role)),
291+
interactiveRoles.filter(role => !recommendedRoles.includes(role)),
295292
triggeringHandlers,
296293
focusableTemplate,
297294
),
@@ -309,15 +306,13 @@ ruleTester.run(`${ruleName}:strict`, rule, {
309306
...passReducer(
310307
interactiveRoles,
311308
eventHandlers.filter(
312-
handler => !includes(triggeringHandlers, handler),
309+
handler => !triggeringHandlers.includes(handler),
313310
),
314311
codeTemplate,
315312
),
316313
...passReducer(
317-
interactiveRoles.filter(role => !includes(strictRoles, role)),
318-
eventHandlers.filter(handler =>
319-
includes(triggeringHandlers, handler),
320-
),
314+
interactiveRoles.filter(role => !strictRoles.includes(role)),
315+
eventHandlers.filter(handler => triggeringHandlers.includes(handler)),
321316
tabindexTemplate,
322317
),
323318
),
@@ -330,7 +325,7 @@ ruleTester.run(`${ruleName}:strict`, rule, {
330325
...neverValid,
331326
...failReducer(strictRoles, triggeringHandlers, tabbableTemplate),
332327
...failReducer(
333-
interactiveRoles.filter(role => !includes(strictRoles, role)),
328+
interactiveRoles.filter(role => !strictRoles.includes(role)),
334329
triggeringHandlers,
335330
focusableTemplate,
336331
),

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-includes": "^3.1.8",
5352
"array.prototype.flatmap": "^1.3.2",
5453
"ast-types-flow": "^0.0.8",
5554
"axe-core": "^4.10.2",

src/rules/control-has-associated-label.js

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

1111
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
1212
import type { JSXElement } from 'ast-types-flow';
13-
import includes from 'array-includes';
1413
import { generateObjSchema, arraySchema } from '../util/schemas';
1514
import type {
1615
ESLintConfig,
@@ -74,7 +73,7 @@ export default ({
7473
return;
7574
}
7675
// Ignore roles that are "interactive" but should not require a label.
77-
if (includes(ignoreRoles, role)) {
76+
if (ignoreRoles.includes(role)) {
7877
return;
7978
}
8079
const props = node.openingElement.attributes;

src/rules/img-redundant-alt.js

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

1111
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
12-
import includes from 'array-includes';
1312
import stringIncludes from 'string.prototype.includes';
1413
import safeRegexTest from 'safe-regex-test';
1514
import { generateObjSchema, arraySchema } from '../util/schemas';
@@ -37,7 +36,7 @@ function containsRedundantWord(value, redundantWords) {
3736
return value
3837
.split(/\s+/)
3938
.some(valueWord =>
40-
includes(lowercaseRedundantWords, valueWord.toLowerCase()),
39+
lowercaseRedundantWords.includes(valueWord.toLowerCase()),
4140
);
4241
}
4342
return lowercaseRedundantWords.some(redundantWord =>

src/rules/interactive-supports-focus.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
hasAnyProp,
1313
} from 'jsx-ast-utils';
1414
import type { JSXOpeningElement } from 'ast-types-flow';
15-
import includes from 'array-includes';
1615
import type {
1716
ESLintConfig,
1817
ESLintContext,
@@ -42,7 +41,7 @@ const schema = generateObjSchema({
4241
!roles.get(name).abstract &&
4342
roles
4443
.get(name)
45-
.superClass.some(klasses => includes(klasses, 'widget')),
44+
.superClass.some(klasses => klasses.includes('widget')),
4645
),
4746
),
4847
});
@@ -110,7 +109,7 @@ export default ({
110109
!hasTabindex
111110
) {
112111
const role = getLiteralPropValue(getProp(attributes, 'role'));
113-
if (includes(tabbable, role)) {
112+
if (tabbable.includes(role)) {
114113
// Always tabbable, tabIndex = 0
115114
context.report({
116115
node,

src/rules/no-interactive-element-to-noninteractive-role.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import { dom } from 'aria-query';
1313
import { getProp, getLiteralPropValue, propName } from 'jsx-ast-utils';
1414
import type { JSXIdentifier } from 'ast-types-flow';
15-
import includes from 'array-includes';
1615
import type {
1716
ESLintConfig,
1817
ESLintContext,
@@ -73,7 +72,7 @@ export default ({
7372
const allowedRoles = options[0] || {};
7473
if (
7574
Object.hasOwn(allowedRoles, type) &&
76-
includes(allowedRoles[type], role)
75+
allowedRoles[type].includes(role)
7776
) {
7877
return;
7978
}

src/rules/no-noninteractive-element-interactions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
propName,
1717
} from 'jsx-ast-utils';
1818
import type { JSXOpeningElement } from 'ast-types-flow';
19-
import includes from 'array-includes';
2019
import type {
2120
ESLintConfig,
2221
ESLintContext,
@@ -70,7 +69,7 @@ export default ({
7069
attributes = attributes.filter(
7170
attr =>
7271
attr.type !== 'JSXSpreadAttribute' &&
73-
!includes(config[type], propName(attr)),
72+
!config[type].includes(propName(attr)),
7473
);
7574
}
7675

src/rules/no-noninteractive-element-to-interactive-role.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import { dom } from 'aria-query';
1313
import { propName } from 'jsx-ast-utils';
1414
import type { JSXIdentifier } from 'ast-types-flow';
15-
import includes from 'array-includes';
1615
import type {
1716
ESLintConfig,
1817
ESLintContext,
@@ -73,7 +72,7 @@ export default ({
7372
const allowedRoles = options[0] || {};
7473
if (
7574
Object.hasOwn(allowedRoles, type) &&
76-
includes(allowedRoles[type], role)
75+
allowedRoles[type].includes(role)
7776
) {
7877
return;
7978
}

0 commit comments

Comments
 (0)