Skip to content

Commit

Permalink
use map instead of object
Browse files Browse the repository at this point in the history
  • Loading branch information
mkszepp committed Jun 21, 2024
1 parent bf4637b commit 0efc746
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/rules/no-runloop.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = {
// List of allowed runloop functions
const allowList = context.options[0]?.allowList ?? [];
// Maps local names to imported names of imports
const localToImportedNameMap = {};
const localToImportedNameMap = new Map();

/**
* Reports a node with usage of a disallowed runloop function
Expand Down Expand Up @@ -107,7 +107,7 @@ module.exports = {
if (spec.type === 'ImportSpecifier') {
const importedName = spec.imported.name;
if (EMBER_RUNLOOP_FUNCTIONS.includes(importedName)) {
localToImportedNameMap[spec.local.name] = importedName;
localToImportedNameMap.set(spec.local.name, importedName);
}
}
}
Expand All @@ -118,9 +118,8 @@ module.exports = {
// Examples: run(...), later(...)
if (node.callee.type === 'Identifier') {
const name = node.callee.name;
const runloopFn = localToImportedNameMap[name];
const isNotAllowed =
runloopFn && !allowList.includes(runloopFn) && !Object.prototype.hasOwnProperty(name);
const runloopFn = localToImportedNameMap.get(name);
const isNotAllowed = runloopFn && !allowList.includes(runloopFn);
if (isNotAllowed) {
report(node, runloopFn, name);
}
Expand All @@ -130,7 +129,7 @@ module.exports = {
// Examples: run.later(...), run.schedule(...)
if (node.callee.type === 'MemberExpression' && node.callee.object?.type === 'Identifier') {
const objectName = node.callee.object.name;
const objectRunloopFn = localToImportedNameMap[objectName];
const objectRunloopFn = localToImportedNameMap.get(objectName);

if (objectRunloopFn === 'run' && node.callee.property?.type === 'Identifier') {
const runloopFn = node.callee.property.name;
Expand Down

0 comments on commit 0efc746

Please sign in to comment.