]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-new-func.js
ddf61024dac54b529c05b0fcbfeedda49667e50f
2 * @fileoverview Rule to flag when using new Function
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const astUtils
= require("./utils/ast-utils");
14 //------------------------------------------------------------------------------
16 //------------------------------------------------------------------------------
18 const callMethods
= new Set(["apply", "bind", "call"]);
20 //------------------------------------------------------------------------------
22 //------------------------------------------------------------------------------
29 description
: "disallow `new` operators with the `Function` object",
31 url
: "https://eslint.org/docs/rules/no-new-func"
37 noFunctionConstructor
: "The Function constructor is eval."
45 const globalScope
= context
.getScope();
46 const variable
= globalScope
.set.get("Function");
48 if (variable
&& variable
.defs
.length
=== 0) {
49 variable
.references
.forEach(ref
=> {
50 const node
= ref
.identifier
;
51 const { parent
} = node
;
55 if (node
=== parent
.callee
&& (
56 parent
.type
=== "NewExpression" ||
57 parent
.type
=== "CallExpression"
61 parent
.type
=== "MemberExpression" &&
62 node
=== parent
.object
&&
63 callMethods
.has(astUtils
.getStaticPropertyName(parent
))
65 const maybeCallee
= parent
.parent
.type
=== "ChainExpression" ? parent
.parent
: parent
;
67 if (maybeCallee
.parent
.type
=== "CallExpression" && maybeCallee
.parent
.callee
=== maybeCallee
) {
68 evalNode
= maybeCallee
.parent
;
76 messageId
: "noFunctionConstructor"