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 | docs: {
|
15 | description: "disallow `new` operators with the `Function` object",
|
16 | category: "Best Practices",
|
17 | recommended: false,
|
18 | url: "https://eslint.org/docs/rules/no-new-func"
|
19 | },
|
20 |
|
21 | schema: []
|
22 | },
|
23 |
|
24 | create(context) {
|
25 |
|
26 | //--------------------------------------------------------------------------
|
27 | // Helpers
|
28 | //--------------------------------------------------------------------------
|
29 |
|
30 | /**
|
31 | * Reports a node.
|
32 | * @param {ASTNode} node The node to report
|
33 | * @returns {void}
|
34 | * @private
|
35 | */
|
36 | function report(node) {
|
37 | context.report({ node, message: "The Function constructor is eval." });
|
38 | }
|
39 |
|
40 | return {
|
41 | "NewExpression[callee.name = 'Function']": report,
|
42 | "CallExpression[callee.name = 'Function']": report
|
43 | };
|
44 |
|
45 | }
|
46 | };
|