Skip to content

Commit

Permalink
[Refactor] use es-iterator-helpers in a couple places
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 8, 2023
1 parent 3c11201 commit f338f79
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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)
);
}
},
};
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/jsx-no-leaked-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions lib/util/propWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f338f79

Please sign in to comment.