Skip to content

Commit 91657d4

Browse files
authored
Merge pull request #2151 from mkszepp/fix-false-positive-no-runloop
Fix false positive error for `no-runloop`
2 parents be09821 + 0efc746 commit 91657d4

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

lib/rules/no-runloop.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = {
7575
// List of allowed runloop functions
7676
const allowList = context.options[0]?.allowList ?? [];
7777
// Maps local names to imported names of imports
78-
const localToImportedNameMap = {};
78+
const localToImportedNameMap = new Map();
7979

8080
/**
8181
* Reports a node with usage of a disallowed runloop function
@@ -107,7 +107,7 @@ module.exports = {
107107
if (spec.type === 'ImportSpecifier') {
108108
const importedName = spec.imported.name;
109109
if (EMBER_RUNLOOP_FUNCTIONS.includes(importedName)) {
110-
localToImportedNameMap[spec.local.name] = importedName;
110+
localToImportedNameMap.set(spec.local.name, importedName);
111111
}
112112
}
113113
}
@@ -118,7 +118,7 @@ module.exports = {
118118
// Examples: run(...), later(...)
119119
if (node.callee.type === 'Identifier') {
120120
const name = node.callee.name;
121-
const runloopFn = localToImportedNameMap[name];
121+
const runloopFn = localToImportedNameMap.get(name);
122122
const isNotAllowed = runloopFn && !allowList.includes(runloopFn);
123123
if (isNotAllowed) {
124124
report(node, runloopFn, name);
@@ -129,7 +129,7 @@ module.exports = {
129129
// Examples: run.later(...), run.schedule(...)
130130
if (node.callee.type === 'MemberExpression' && node.callee.object?.type === 'Identifier') {
131131
const objectName = node.callee.object.name;
132-
const objectRunloopFn = localToImportedNameMap[objectName];
132+
const objectRunloopFn = localToImportedNameMap.get(objectName);
133133

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

tests/lib/rules/no-runloop.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,39 @@ eslintTester.run('no-runloop', rule, {
6565
`,
6666
options: [{ allowList: ['later'] }],
6767
},
68+
`
69+
function hasOwnProperty() {};
70+
hasOwnProperty();
71+
72+
function isPrototypeOf() {};
73+
isPrototypeOf();
74+
75+
function propertyIsEnumerable() {};
76+
propertyIsEnumerable();
77+
78+
function toLocaleString() {};
79+
toLocaleString();
80+
81+
function toString() {};
82+
toString();
83+
84+
function valueOf() {};
85+
valueOf();
86+
87+
function constructor() {};
88+
constructor();
89+
`,
90+
`
91+
import { hasOwnProperty, isPrototypeOf, propertyIsEnumerable, toLocaleString, toString, valueOf, constructor } from './util';
92+
93+
hasOwnProperty();
94+
isPrototypeOf();
95+
propertyIsEnumerable();
96+
toLocaleString();
97+
toString();
98+
valueOf();
99+
constructor();
100+
`,
68101
],
69102
invalid: [
70103
{

0 commit comments

Comments
 (0)