Skip to content

Commit

Permalink
Merge pull request #2151 from mkszepp/fix-false-positive-no-runloop
Browse files Browse the repository at this point in the history
Fix false positive error for `no-runloop`
  • Loading branch information
ef4 authored Jun 21, 2024
2 parents be09821 + 0efc746 commit 91657d4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
8 changes: 4 additions & 4 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,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);
Expand All @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions tests/lib/rules/no-runloop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down

0 comments on commit 91657d4

Please sign in to comment.