Skip to content

Commit 22fb09a

Browse files
committed
[Refactor] use es-iterator-helpers in a couple places
1 parent ae64aa8 commit 22fb09a

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

lib/rules/display-name.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
'use strict';
77

88
const values = require('object.values');
9+
const filter = require('es-iterator-helpers/Iterator.prototype.filter');
10+
const forEach = require('es-iterator-helpers/Iterator.prototype.forEach');
911

1012
const Components = require('../util/Components');
1113
const isCreateContext = require('../util/isCreateContext');
@@ -270,8 +272,10 @@ module.exports = {
270272
});
271273
if (checkContextObjects) {
272274
// Report missing display name for all context objects
273-
const contextsList = Array.from(contextObjects.values()).filter((v) => !v.hasDisplayName);
274-
contextsList.forEach((contextObj) => reportMissingContextDisplayName(contextObj));
275+
forEach(
276+
filter(contextObjects.values(), (v) => !v.hasDisplayName),
277+
(contextObj) => reportMissingContextDisplayName(contextObj)
278+
);
275279
}
276280
},
277281
};

lib/rules/jsx-no-leaked-render.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
'use strict';
77

8+
const find = require('es-iterator-helpers/Iterator.prototype.find');
9+
const from = require('es-iterator-helpers/Iterator.from');
10+
811
const docsUrl = require('../util/docsUrl');
912
const report = require('../util/report');
1013
const testReactVersion = require('../util/version').testReactVersion;
@@ -135,7 +138,7 @@ module.exports = {
135138
create(context) {
136139
const config = context.options[0] || {};
137140
const validStrategies = new Set(config.validStrategies || DEFAULT_VALID_STRATEGIES);
138-
const fixStrategy = Array.from(validStrategies)[0];
141+
const fixStrategy = find(from(validStrategies), () => true);
139142

140143
return {
141144
'JSXExpressionContainer > LogicalExpression[operator="&&"]'(node) {

lib/util/propWrapper.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
'use strict';
66

7+
const from = require('es-iterator-helpers/Iterator.from');
8+
const filter = require('es-iterator-helpers/Iterator.prototype.filter');
9+
const some = require('es-iterator-helpers/Iterator.prototype.some');
10+
711
function searchPropWrapperFunctions(name, propWrapperFunctions) {
812
const splitName = name.split('.');
9-
return Array.from(propWrapperFunctions).some((func) => {
13+
return some(from(propWrapperFunctions), (func) => {
1014
if (splitName.length === 2 && func.object === splitName[0] && func.property === splitName[1]) {
1115
return true;
1216
}
@@ -28,7 +32,7 @@ function isPropWrapperFunction(context, name) {
2832

2933
function getExactPropWrapperFunctions(context) {
3034
const propWrapperFunctions = getPropWrapperFunctions(context);
31-
const exactPropWrappers = Array.from(propWrapperFunctions).filter((func) => func.exact === true);
35+
const exactPropWrappers = filter(from(propWrapperFunctions), (func) => func.exact === true);
3236
return new Set(exactPropWrappers);
3337
}
3438

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"array.prototype.flatmap": "^1.3.1",
3030
"array.prototype.tosorted": "^1.1.1",
3131
"doctrine": "^2.1.0",
32+
"es-iterator-helpers": "^1.0.11",
3233
"estraverse": "^5.3.0",
3334
"jsx-ast-utils": "^2.4.1 || ^3.0.0",
3435
"minimatch": "^3.1.2",

0 commit comments

Comments
 (0)