-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
no-new-func.js
49 lines (43 loc) · 1.41 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
/**
* @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
}
},
"function Function() {}; 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"
}]
}
]
});