Skip to content

Commit 874732b

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 d20bd65 commit 874732b

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,
@@ -213,12 +212,12 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
213212
...alwaysValid,
214213
...passReducer(
215214
interactiveRoles,
216-
eventHandlers.filter((handler) => !includes(triggeringHandlers, handler)),
215+
eventHandlers.filter((handler) => !triggeringHandlers.includes(handler)),
217216
codeTemplate,
218217
),
219218
...passReducer(
220-
interactiveRoles.filter((role) => !includes(recommendedRoles, role)),
221-
eventHandlers.filter((handler) => includes(triggeringHandlers, handler)),
219+
interactiveRoles.filter((role) => !recommendedRoles.includes(role)),
220+
eventHandlers.filter((handler) => triggeringHandlers.includes(handler)),
222221
tabindexTemplate,
223222
),
224223
))
@@ -228,7 +227,7 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
228227
...neverValid,
229228
...failReducer(recommendedRoles, triggeringHandlers, tabbableTemplate),
230229
...failReducer(
231-
interactiveRoles.filter((role) => !includes(recommendedRoles, role)),
230+
interactiveRoles.filter((role) => !recommendedRoles.includes(role)),
232231
triggeringHandlers,
233232
focusableTemplate,
234233
),
@@ -242,12 +241,12 @@ ruleTester.run(`${ruleName}:strict`, rule, {
242241
...alwaysValid,
243242
...passReducer(
244243
interactiveRoles,
245-
eventHandlers.filter((handler) => !includes(triggeringHandlers, handler)),
244+
eventHandlers.filter((handler) => !triggeringHandlers.includes(handler)),
246245
codeTemplate,
247246
),
248247
...passReducer(
249-
interactiveRoles.filter((role) => !includes(strictRoles, role)),
250-
eventHandlers.filter((handler) => includes(triggeringHandlers, handler)),
248+
interactiveRoles.filter((role) => !strictRoles.includes(role)),
249+
eventHandlers.filter((handler) => triggeringHandlers.includes(handler)),
251250
tabindexTemplate,
252251
),
253252
))
@@ -257,7 +256,7 @@ ruleTester.run(`${ruleName}:strict`, rule, {
257256
...neverValid,
258257
...failReducer(strictRoles, triggeringHandlers, tabbableTemplate),
259258
...failReducer(
260-
interactiveRoles.filter((role) => !includes(strictRoles, role)),
259+
interactiveRoles.filter((role) => !strictRoles.includes(role)),
261260
triggeringHandlers,
262261
focusableTemplate,
263262
),

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",
@@ -89,8 +88,7 @@
8988
"language-tags": "^1.0.9",
9089
"minimatch": "^3.1.2",
9190
"object.fromentries": "^2.0.8",
92-
"safe-regex-test": "^1.0.3",
93-
"string.prototype.includes": "^2.0.1"
91+
"safe-regex-test": "^1.0.3"
9492
},
9593
"peerDependencies": {
9694
"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,
@@ -39,7 +38,7 @@ const schema = generateObjSchema({
3938
// TODO: convert to use iterFilter and iterFrom
4039
tabbable: enumArraySchema([...roles.keys()].filter((name) => (
4140
!roles.get(name).abstract
42-
&& roles.get(name).superClass.some((klasses) => includes(klasses, 'widget'))
41+
&& roles.get(name).superClass.some((klasses) => klasses.includes('widget'))
4342
))),
4443
});
4544

@@ -95,7 +94,7 @@ export default ({
9594
&& !hasTabindex
9695
) {
9796
const role = getLiteralPropValue(getProp(attributes, 'role'));
98-
if (includes(tabbable, role)) {
97+
if (tabbable.includes(role)) {
9998
// Always tabbable, tabIndex = 0
10099
context.report({
101100
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)