From d20c16e440a73764e7450139bc6b5c0afbd60b0b Mon Sep 17 00:00:00 2001 From: archmoj Date: Fri, 30 Jul 2021 10:44:14 -0400 Subject: [PATCH] Fix: no-new-fuc should catch calls to Function.apply --- lib/rules/no-new-func.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/rules/no-new-func.js b/lib/rules/no-new-func.js index 9af4e31cabf..bfe845c470b 100644 --- a/lib/rules/no-new-func.js +++ b/lib/rules/no-new-func.js @@ -38,12 +38,23 @@ module.exports = { variable.references.forEach(ref => { const node = ref.identifier; const { parent } = node; + var isEval = false; - if ( - parent && - (parent.type === "NewExpression" || parent.type === "CallExpression") && - node === parent.callee - ) { + if (parent) { + if (node === parent.callee && ( + parent.type === "NewExpression" || + parent.type === "CallExpression" + )) { + isEval = true; + } else if (parent.type === "MemberExpression") { + var gParent = parent.parent; + if (gParent && gParent.type === "CallExpression") { + isEval = true; + } + } + } + + if(isEval) { context.report({ node: parent, messageId: "noFunctionConstructor"