]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-new-func.js
aa0542090e24229bf28b5b1948b252bea1030bb3
[pve-eslint.git] / eslint / tests / lib / rules / no-new-func.js
1 /**
2 * @fileoverview Tests for no-new-func rule.
3 * @author Ilya Volodin
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/no-new-func"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("no-new-func", rule, {
22 valid: [
23 "var a = new _function(\"b\", \"c\", \"return b+c\");",
24 "var a = _function(\"b\", \"c\", \"return b+c\");",
25 {
26 code: "class Function {}; new Function()",
27 parserOptions: {
28 ecmaVersion: 2015
29 }
30 },
31 {
32 code: "const fn = () => { class Function {}; new Function() }",
33 parserOptions: {
34 ecmaVersion: 2015
35 }
36 },
37 "function Function() {}; Function()",
38 "var fn = function () { function Function() {}; Function() }",
39 "var x = function Function() { Function(); }",
40 "call(Function)",
41 "new Class(Function)"
42 ],
43 invalid: [
44 {
45 code: "var a = new Function(\"b\", \"c\", \"return b+c\");",
46 errors: [{
47 messageId: "noFunctionConstructor",
48 type: "NewExpression"
49 }]
50 },
51 {
52 code: "var a = Function(\"b\", \"c\", \"return b+c\");",
53 errors: [{
54 messageId: "noFunctionConstructor",
55 type: "CallExpression"
56 }]
57 },
58 {
59 code: "const fn = () => { class Function {} }; new Function('', '')",
60 parserOptions: {
61 ecmaVersion: 2015
62 },
63 errors: [{
64 messageId: "noFunctionConstructor",
65 type: "NewExpression"
66 }]
67 },
68 {
69 code: "var fn = function () { function Function() {} }; Function('', '')",
70 errors: [{
71 messageId: "noFunctionConstructor",
72 type: "CallExpression"
73 }]
74 }
75 ]
76 });