Skip to content

Commit 44394d4

Browse files
committed
[Refactor] remove array-includes, string.prototype.includes
node 12+ has a working version, and given that this is an eslint plugin, the robustness it provides is not needed
1 parent f4b80d1 commit 44394d4

17 files changed

+35
-54
lines changed

__mocks__/genInteractives.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
import { dom, roles } from 'aria-query';
6-
import includes from 'array-includes';
76
import fromEntries from 'object.fromentries';
87

98
import JSXAttributeMock from './JSXAttributeMock';
@@ -141,17 +140,17 @@ const interactiveRoles = []
141140
)
142141
.filter((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
148147
.filter((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

152151
// 'toolbar' does not descend from widget, but it does support
153152
// aria-activedescendant, thus in practice we treat it as a widget.
154-
&& !includes(['toolbar'], role)
153+
&& role !== 'toolbar'
155154
));
156155

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

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

Lines changed: 8 additions & 9 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 {
1312
eventHandlers,
@@ -205,12 +204,12 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
205204
...alwaysValid,
206205
...passReducer(
207206
interactiveRoles,
208-
eventHandlers.filter((handler) => !includes(triggeringHandlers, handler)),
207+
eventHandlers.filter((handler) => !triggeringHandlers.includes(handler)),
209208
codeTemplate,
210209
),
211210
...passReducer(
212-
interactiveRoles.filter((role) => !includes(recommendedRoles, role)),
213-
eventHandlers.filter((handler) => includes(triggeringHandlers, handler)),
211+
interactiveRoles.filter((role) => !recommendedRoles.includes(role)),
212+
eventHandlers.filter((handler) => triggeringHandlers.includes(handler)),
214213
tabindexTemplate,
215214
),
216215
))
@@ -220,7 +219,7 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
220219
...neverValid,
221220
...failReducer(recommendedRoles, triggeringHandlers, tabbableTemplate),
222221
...failReducer(
223-
interactiveRoles.filter((role) => !includes(recommendedRoles, role)),
222+
interactiveRoles.filter((role) => !recommendedRoles.includes(role)),
224223
triggeringHandlers,
225224
focusableTemplate,
226225
),
@@ -234,12 +233,12 @@ ruleTester.run(`${ruleName}:strict`, rule, {
234233
...alwaysValid,
235234
...passReducer(
236235
interactiveRoles,
237-
eventHandlers.filter((handler) => !includes(triggeringHandlers, handler)),
236+
eventHandlers.filter((handler) => !triggeringHandlers.includes(handler)),
238237
codeTemplate,
239238
),
240239
...passReducer(
241-
interactiveRoles.filter((role) => !includes(strictRoles, role)),
242-
eventHandlers.filter((handler) => includes(triggeringHandlers, handler)),
240+
interactiveRoles.filter((role) => !strictRoles.includes(role)),
241+
eventHandlers.filter((handler) => triggeringHandlers.includes(handler)),
243242
tabindexTemplate,
244243
),
245244
))
@@ -249,7 +248,7 @@ ruleTester.run(`${ruleName}:strict`, rule, {
249248
...neverValid,
250249
...failReducer(strictRoles, triggeringHandlers, tabbableTemplate),
251250
...failReducer(
252-
interactiveRoles.filter((role) => !includes(strictRoles, role)),
251+
interactiveRoles.filter((role) => !strictRoles.includes(role)),
253252
triggeringHandlers,
254253
focusableTemplate,
255254
),

package.json

Lines changed: 1 addition & 3 deletions
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-includes": "^3.1.8",
8079
"array.prototype.flatmap": "^1.3.2",
8180
"ast-types-flow": "^0.0.8",
8281
"axe-core": "^4.10.0",
@@ -88,8 +87,7 @@
8887
"language-tags": "^1.0.9",
8988
"minimatch": "^3.1.2",
9089
"object.fromentries": "^2.0.8",
91-
"safe-regex-test": "^1.0.3",
92-
"string.prototype.includes": "^2.0.1"
90+
"safe-regex-test": "^1.0.3"
9391
},
9492
"peerDependencies": {
9593
"eslint": "^8.8 || ^9.13"

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

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

1212
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
1313
import type { JSXElement } from 'ast-types-flow';
14-
import includes from 'array-includes';
1514
import { generateObjSchema, arraySchema } from '../util/schemas';
1615
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
1716
import getElementType from '../util/getElementType';
@@ -68,7 +67,7 @@ export default ({
6867
return;
6968
}
7069
// Ignore roles that are "interactive" but should not require a label.
71-
if (includes(ignoreRoles, role)) {
70+
if (ignoreRoles.includes(role)) {
7271
return;
7372
}
7473
const props = node.openingElement.attributes;

src/rules/img-redundant-alt.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// ----------------------------------------------------------------------------
99

1010
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
11-
import includes from 'array-includes';
12-
import stringIncludes from 'string.prototype.includes';
1311
import safeRegexTest from 'safe-regex-test';
1412
import { generateObjSchema, arraySchema } from '../util/schemas';
1513
import getElementType from '../util/getElementType';
@@ -34,9 +32,9 @@ function containsRedundantWord(value, redundantWords) {
3432
const lowercaseRedundantWords = redundantWords.map((redundantWord) => redundantWord.toLowerCase());
3533

3634
if (isASCII(value)) {
37-
return value.split(/\s+/).some((valueWord) => includes(lowercaseRedundantWords, valueWord.toLowerCase()));
35+
return value.split(/\s+/).some((valueWord) => lowercaseRedundantWords.includes(valueWord.toLowerCase()));
3836
}
39-
return lowercaseRedundantWords.some((redundantWord) => stringIncludes(value.toLowerCase(), redundantWord));
37+
return lowercaseRedundantWords.some((redundantWord) => value.toLowerCase().includes(redundantWord));
4038
}
4139

4240
export default {

src/rules/interactive-supports-focus.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
hasAnyProp,
1616
} from 'jsx-ast-utils';
1717
import type { JSXOpeningElement } from 'ast-types-flow';
18-
import includes from 'array-includes';
1918
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2019
import {
2120
enumArraySchema,
@@ -38,7 +37,7 @@ import getTabIndex from '../util/getTabIndex';
3837
const schema = generateObjSchema({
3938
tabbable: enumArraySchema(roles.keys().filter((name) => (
4039
!roles.get(name).abstract
41-
&& roles.get(name).superClass.some((klasses) => includes(klasses, 'widget'))
40+
&& roles.get(name).superClass.some((klasses) => klasses.includes('widget'))
4241
))),
4342
});
4443

@@ -94,7 +93,7 @@ export default ({
9493
&& !hasTabindex
9594
) {
9695
const role = getLiteralPropValue(getProp(attributes, 'role'));
97-
if (includes(tabbable, role)) {
96+
if (tabbable.includes(role)) {
9897
// Always tabbable, tabIndex = 0
9998
context.report({
10099
node,

src/rules/no-interactive-element-to-noninteractive-role.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 { JSXIdentifier } from 'ast-types-flow';
19-
import includes from 'array-includes';
2019
import hasOwn from 'hasown';
2120
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2221
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
@@ -68,7 +67,7 @@ export default ({
6867
// Allow overrides from rule configuration for specific elements and
6968
// roles.
7069
const allowedRoles = (options[0] || {});
71-
if (hasOwn(allowedRoles, type) && includes(allowedRoles[type], role)) {
70+
if (hasOwn(allowedRoles, type) && allowedRoles[type].includes(role)) {
7271
return;
7372
}
7473
if (

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 hasOwn from 'hasown';
2120
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2221
import { arraySchema, generateObjSchema } from '../util/schemas';
@@ -62,7 +61,7 @@ export default ({
6261
const interactiveProps = config.handlers || defaultInteractiveProps;
6362
// Allow overrides from rule configuration for specific elements and roles.
6463
if (hasOwn(config, type)) {
65-
attributes = attributes.filter((attr) => attr.type !== 'JSXSpreadAttribute' && !includes(config[type], propName(attr)));
64+
attributes = attributes.filter((attr) => attr.type !== 'JSXSpreadAttribute' && !config[type].includes(propName(attr)));
6665
}
6766

6867
const hasInteractiveProps = interactiveProps

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
propName,
1515
} from 'jsx-ast-utils';
1616
import type { JSXIdentifier } from 'ast-types-flow';
17-
import includes from 'array-includes';
1817
import hasOwn from 'hasown';
1918
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2019
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
@@ -66,7 +65,7 @@ export default ({
6665
// Allow overrides from rule configuration for specific elements and
6766
// roles.
6867
const allowedRoles = (options[0] || {});
69-
if (hasOwn(allowedRoles, type) && includes(allowedRoles[type], role)) {
68+
if (hasOwn(allowedRoles, type) && allowedRoles[type].includes(role)) {
7069
return;
7170
}
7271
if (

src/rules/no-noninteractive-tabindex.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
getProp,
1515
getLiteralPropValue,
1616
} from 'jsx-ast-utils';
17-
import includes from 'array-includes';
1817
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
1918
import getElementType from '../util/getElementType';
2019
import isInteractiveElement from '../util/isInteractiveElement';
@@ -71,10 +70,10 @@ export default ({
7170
roles,
7271
allowExpressionValues,
7372
} = (options[0] || {});
74-
if (tags && includes(tags, type)) {
73+
if (tags && tags.includes(type)) {
7574
return;
7675
}
77-
if (roles && includes(roles, role)) {
76+
if (roles && roles.includes(role)) {
7877
return;
7978
}
8079
if (

0 commit comments

Comments
 (0)