diff --git a/lib/rules/no-runloop.js b/lib/rules/no-runloop.js index 84de1db172..b889bf390d 100644 --- a/lib/rules/no-runloop.js +++ b/lib/rules/no-runloop.js @@ -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 @@ -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); } } } @@ -118,7 +118,7 @@ module.exports = { // Examples: run(...), later(...) if (node.callee.type === 'Identifier') { const name = node.callee.name; - const runloopFn = localToImportedNameMap[name]; + const runloopFn = localToImportedNameMap.get(name); const isNotAllowed = runloopFn && !allowList.includes(runloopFn); if (isNotAllowed) { report(node, runloopFn, name); @@ -129,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; diff --git a/tests/lib/rules/no-runloop.js b/tests/lib/rules/no-runloop.js index e7d75c3c63..f20b12f5de 100644 --- a/tests/lib/rules/no-runloop.js +++ b/tests/lib/rules/no-runloop.js @@ -65,6 +65,39 @@ eslintTester.run('no-runloop', rule, { `, options: [{ allowList: ['later'] }], }, + ` + function hasOwnProperty() {}; + hasOwnProperty(); + + function isPrototypeOf() {}; + isPrototypeOf(); + + function propertyIsEnumerable() {}; + propertyIsEnumerable(); + + function toLocaleString() {}; + toLocaleString(); + + function toString() {}; + toString(); + + function valueOf() {}; + valueOf(); + + function constructor() {}; + constructor(); + `, + ` + import { hasOwnProperty, isPrototypeOf, propertyIsEnumerable, toLocaleString, toString, valueOf, constructor } from './util'; + + hasOwnProperty(); + isPrototypeOf(); + propertyIsEnumerable(); + toLocaleString(); + toString(); + valueOf(); + constructor(); + `, ], invalid: [ {