Skip to content

Commit

Permalink
fix(eslint-plugin-experience): use Set for optimize search expression
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Mar 25, 2024
1 parent b6e9573 commit a545426
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
24 changes: 10 additions & 14 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
{
"tasksRunnerOptions": {
"default": {
"runner": "nx-cloud",
"options": {
"cacheableOperations": ["test", "build"],
"parallel": 1
}
}
},
"affected": {
"defaultBase": "origin/main"
},
"workspaceLayout": {
"libsDir": "projects",
"appsDir": "projects"
Expand All @@ -28,6 +16,14 @@
],
"production": ["default"]
},
"targetDefaults": {},
"nxCloudAccessToken": "ZmQxN2Q4MmQtNzQ3OC00MDQ0LTg2MTYtNGE3OGU5NDQwNTk3fHJlYWQtd3JpdGU="
"targetDefaults": {
"test": {
"cache": true
},
"build": {
"cache": true
}
},
"defaultBase": "origin/main",
"parallel": 1
}
19 changes: 11 additions & 8 deletions projects/eslint-plugin-experience/rules/no-simple-for-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ module.exports = {
* @return {*}
*/
ForOfStatement(node) {
const isSimpleForOf = !findExpressions(node, [
'AwaitExpression',
'YieldExpression',
'BreakStatement',
'ContinueStatement',
'ReturnStatement',
]);
const isSimpleForOf = !findExpressions(
node,
new Set([
'AwaitExpression',
'YieldExpression',
'BreakStatement',
'ContinueStatement',
'ReturnStatement',
]),
);

if (isSimpleForOf) {
context.report({
Expand All @@ -33,7 +36,7 @@ module.exports = {
};

function findExpressions(node, keys) {
if (keys.includes(node?.type) || keys.includes(node?.expression?.type)) {
if (keys.has(node?.type) || keys.has(node?.expression?.type)) {
return true;
}

Expand Down

0 comments on commit a545426

Please sign in to comment.