Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positive error for no-runloop #2151

Merged
merged 5 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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