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