diff --git a/lib/rules/display-name.js b/lib/rules/display-name.js index 9a3d7e4e24..be0e2985b3 100644 --- a/lib/rules/display-name.js +++ b/lib/rules/display-name.js @@ -6,6 +6,8 @@ 'use strict'; const values = require('object.values'); +const filter = require('es-iterator-helpers/Iterator.prototype.filter'); +const forEach = require('es-iterator-helpers/Iterator.prototype.forEach'); const Components = require('../util/Components'); const isCreateContext = require('../util/isCreateContext'); @@ -270,8 +272,10 @@ module.exports = { }); if (checkContextObjects) { // Report missing display name for all context objects - const contextsList = Array.from(contextObjects.values()).filter((v) => !v.hasDisplayName); - contextsList.forEach((contextObj) => reportMissingContextDisplayName(contextObj)); + forEach( + filter(contextObjects.values(), (v) => !v.hasDisplayName), + (contextObj) => reportMissingContextDisplayName(contextObj) + ); } }, }; diff --git a/lib/rules/jsx-no-leaked-render.js b/lib/rules/jsx-no-leaked-render.js index c36042bc1d..0fcf407fbd 100644 --- a/lib/rules/jsx-no-leaked-render.js +++ b/lib/rules/jsx-no-leaked-render.js @@ -5,6 +5,9 @@ 'use strict'; +const find = require('es-iterator-helpers/Iterator.prototype.find'); +const from = require('es-iterator-helpers/Iterator.from'); + const docsUrl = require('../util/docsUrl'); const report = require('../util/report'); const testReactVersion = require('../util/version').testReactVersion; @@ -135,7 +138,7 @@ module.exports = { create(context) { const config = context.options[0] || {}; const validStrategies = new Set(config.validStrategies || DEFAULT_VALID_STRATEGIES); - const fixStrategy = Array.from(validStrategies)[0]; + const fixStrategy = find(from(validStrategies), () => true); return { 'JSXExpressionContainer > LogicalExpression[operator="&&"]'(node) { diff --git a/lib/util/propWrapper.js b/lib/util/propWrapper.js index 6b24c4eb18..729e000959 100644 --- a/lib/util/propWrapper.js +++ b/lib/util/propWrapper.js @@ -4,9 +4,13 @@ 'use strict'; +const from = require('es-iterator-helpers/Iterator.from'); +const filter = require('es-iterator-helpers/Iterator.prototype.filter'); +const some = require('es-iterator-helpers/Iterator.prototype.some'); + function searchPropWrapperFunctions(name, propWrapperFunctions) { const splitName = name.split('.'); - return Array.from(propWrapperFunctions).some((func) => { + return some(from(propWrapperFunctions), (func) => { if (splitName.length === 2 && func.object === splitName[0] && func.property === splitName[1]) { return true; } @@ -28,7 +32,7 @@ function isPropWrapperFunction(context, name) { function getExactPropWrapperFunctions(context) { const propWrapperFunctions = getPropWrapperFunctions(context); - const exactPropWrappers = Array.from(propWrapperFunctions).filter((func) => func.exact === true); + const exactPropWrappers = filter(from(propWrapperFunctions), (func) => func.exact === true); return new Set(exactPropWrappers); } diff --git a/package.json b/package.json index b1fa86fa87..eccccbd183 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "array.prototype.flatmap": "^1.3.1", "array.prototype.tosorted": "^1.1.1", "doctrine": "^2.1.0", + "es-iterator-helpers": "^1.0.11", "estraverse": "^5.3.0", "jsx-ast-utils": "^2.4.1 || ^3.0.0", "minimatch": "^3.1.2",