1 | /**
|
2 | * @fileoverview Rule to flag when using new Function
|
3 | * @author Ilya Volodin
|
4 | */
|
5 |
|
6 | ;
|
7 |
|
8 | //------------------------------------------------------------------------------
|
9 | // Rule Definition
|
10 | //------------------------------------------------------------------------------
|
11 |
|
12 | module.exports = {
|
13 | meta: {
|
14 | type: "suggestion",
|
15 |
|
16 | docs: {
|
17 | description: "disallow `new` operators with the `Function` object",
|
18 | category: "Best Practices",
|
19 | recommended: false,
|
20 | url: "https://eslint.org/docs/rules/no-new-func"
|
21 | },
|
22 |
|
23 | schema: []
|
24 | },
|
25 |
|
26 | create(context) {
|
27 |
|
28 | //--------------------------------------------------------------------------
|
29 | // Helpers
|
30 | //--------------------------------------------------------------------------
|
31 |
|
32 | /**
|
33 | * Reports a node.
|
34 | * @param {ASTNode} node The node to report
|
35 | * @returns {void}
|
36 | * @private
|
37 | */
|
38 | function report(node) {
|
39 | context.report({ node, message: "The Function constructor is eval." });
|
40 | }
|
41 |
|
42 | return {
|
43 | "NewExpression[callee.name = 'Function']": report,
|
44 | "CallExpression[callee.name = 'Function']": report
|
45 | };
|
46 |
|
47 | }
|
48 | };
|