@@ -24,9 +24,27 @@ ruleTester.run("no-obj-calls", rule, {
24
24
"var x = Math.random();" ,
25
25
"var x = Math.PI;" ,
26
26
"var x = foo.Math();" ,
27
+ "var x = new foo.Math();" ,
28
+ "var x = new Math.foo;" ,
29
+ "var x = new Math.foo();" ,
27
30
"JSON.parse(foo)" ,
28
- "Reflect.get(foo, 'x')" ,
29
- "Atomics.load(foo, 0)" ,
31
+ "new JSON.parse" ,
32
+ {
33
+ code : "Reflect.get(foo, 'x')" ,
34
+ env : { es6 : true }
35
+ } ,
36
+ {
37
+ code : "new Reflect.foo(a, b)" ,
38
+ env : { es6 : true }
39
+ } ,
40
+ {
41
+ code : "Atomics.load(foo, 0)" ,
42
+ env : { es2017 : true }
43
+ } ,
44
+ {
45
+ code : "new Atomics.foo()" ,
46
+ env : { es2017 : true }
47
+ } ,
30
48
31
49
{ code : "globalThis.Math();" , env : { es6 : true } } ,
32
50
{ code : "var x = globalThis.Math();" , env : { es6 : true } } ,
@@ -43,33 +61,56 @@ ruleTester.run("no-obj-calls", rule, {
43
61
44
62
// non-existing variables
45
63
"/*globals Math: off*/ Math();" ,
64
+ "/*globals Math: off*/ new Math();" ,
46
65
{
47
66
code : "JSON();" ,
48
67
globals : { JSON : "off" }
49
68
} ,
69
+ {
70
+ code : "new JSON();" ,
71
+ globals : { JSON : "off" }
72
+ } ,
50
73
"Reflect();" ,
51
74
"Atomics();" ,
75
+ "new Reflect();" ,
76
+ "new Atomics();" ,
52
77
{
53
78
code : "Atomics();" ,
54
79
env : { es6 : true }
55
80
} ,
56
81
57
82
// shadowed variables
58
83
"var Math; Math();" ,
84
+ "var Math; new Math();" ,
59
85
{
60
86
code : "let JSON; JSON();" ,
61
87
parserOptions : { ecmaVersion : 2015 }
62
88
} ,
89
+ {
90
+ code : "let JSON; new JSON();" ,
91
+ parserOptions : { ecmaVersion : 2015 }
92
+ } ,
63
93
{
64
94
code : "if (foo) { const Reflect = 1; Reflect(); }" ,
65
95
parserOptions : { ecmaVersion : 2015 } ,
66
96
env : { es6 : true }
67
97
} ,
98
+ {
99
+ code : "if (foo) { const Reflect = 1; new Reflect(); }" ,
100
+ parserOptions : { ecmaVersion : 2015 } ,
101
+ env : { es6 : true }
102
+ } ,
68
103
"function foo(Math) { Math(); }" ,
104
+ "function foo(JSON) { new JSON(); }" ,
69
105
{
70
106
code : "function foo(Atomics) { Atomics(); }" ,
71
107
env : { es2017 : true }
72
108
} ,
109
+ {
110
+ code : "function foo() { if (bar) { let Atomics; if (baz) { new Atomics(); } } }" ,
111
+ parserOptions : { ecmaVersion : 2015 } ,
112
+ env : { es2017 : true }
113
+ } ,
73
114
"function foo() { var JSON; JSON(); }" ,
74
115
{
75
116
code : "function foo() { var Atomics = bar(); var baz = Atomics(5); }" ,
@@ -81,12 +122,10 @@ ruleTester.run("no-obj-calls", rule, {
81
122
}
82
123
] ,
83
124
invalid : [
84
-
85
125
{
86
126
code : "Math();" ,
87
127
errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "CallExpression" } ]
88
128
} ,
89
-
90
129
{
91
130
code : "var x = Math();" ,
92
131
errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "CallExpression" } ]
@@ -99,6 +138,26 @@ ruleTester.run("no-obj-calls", rule, {
99
138
code : "Math().foo;" ,
100
139
errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "CallExpression" , column : 1 , endColumn : 7 } ]
101
140
} ,
141
+ {
142
+ code : "new Math;" ,
143
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "NewExpression" } ]
144
+ } ,
145
+ {
146
+ code : "new Math();" ,
147
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "NewExpression" } ]
148
+ } ,
149
+ {
150
+ code : "new Math(foo);" ,
151
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "NewExpression" } ]
152
+ } ,
153
+ {
154
+ code : "new Math().foo;" ,
155
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "NewExpression" } ]
156
+ } ,
157
+ {
158
+ code : "(new Math).foo();" ,
159
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "NewExpression" } ]
160
+ } ,
102
161
{
103
162
code : "var x = JSON();" ,
104
163
errors : [ { messageId : "unexpectedCall" , data : { name : "JSON" } , type : "CallExpression" } ]
@@ -107,6 +166,10 @@ ruleTester.run("no-obj-calls", rule, {
107
166
code : "x = JSON(str);" ,
108
167
errors : [ { messageId : "unexpectedCall" , data : { name : "JSON" } , type : "CallExpression" } ]
109
168
} ,
169
+ {
170
+ code : "var x = new JSON();" ,
171
+ errors : [ { messageId : "unexpectedCall" , data : { name : "JSON" } , type : "NewExpression" } ]
172
+ } ,
110
173
{
111
174
code : "Math( JSON() );" ,
112
175
errors : [
@@ -119,6 +182,11 @@ ruleTester.run("no-obj-calls", rule, {
119
182
env : { es6 : true } ,
120
183
errors : [ { messageId : "unexpectedCall" , data : { name : "Reflect" } , type : "CallExpression" } ]
121
184
} ,
185
+ {
186
+ code : "var x = new Reflect();" ,
187
+ env : { es6 : true } ,
188
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Reflect" } , type : "NewExpression" } ]
189
+ } ,
122
190
{
123
191
code : "var x = Reflect();" ,
124
192
env : { es2017 : true } ,
@@ -128,11 +196,20 @@ ruleTester.run("no-obj-calls", rule, {
128
196
code : "/*globals Reflect: true*/ Reflect();" ,
129
197
errors : [ { messageId : "unexpectedCall" , data : { name : "Reflect" } , type : "CallExpression" } ]
130
198
} ,
199
+ {
200
+ code : "/*globals Reflect: true*/ new Reflect();" ,
201
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Reflect" } , type : "NewExpression" } ]
202
+ } ,
131
203
{
132
204
code : "var x = Atomics();" ,
133
205
env : { es2017 : true } ,
134
206
errors : [ { messageId : "unexpectedCall" , data : { name : "Atomics" } , type : "CallExpression" } ]
135
207
} ,
208
+ {
209
+ code : "var x = new Atomics();" ,
210
+ env : { es2017 : true } ,
211
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Atomics" } , type : "NewExpression" } ]
212
+ } ,
136
213
{
137
214
code : "var x = Atomics();" ,
138
215
env : { es2020 : true } ,
@@ -143,11 +220,21 @@ ruleTester.run("no-obj-calls", rule, {
143
220
globals : { Atomics : false } ,
144
221
errors : [ { messageId : "unexpectedCall" , data : { name : "Atomics" } , type : "CallExpression" } ]
145
222
} ,
223
+ {
224
+ code : "var x = new Atomics();" ,
225
+ globals : { Atomics : "writable" } ,
226
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Atomics" } , type : "NewExpression" } ]
227
+ } ,
146
228
{
147
229
code : "var x = globalThis.Math();" ,
148
230
env : { es2020 : true } ,
149
231
errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "CallExpression" } ]
150
232
} ,
233
+ {
234
+ code : "var x = new globalThis.Math();" ,
235
+ env : { es2020 : true } ,
236
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "NewExpression" } ]
237
+ } ,
151
238
{
152
239
code : "f(globalThis.Math());" ,
153
240
env : { es2020 : true } ,
@@ -158,6 +245,11 @@ ruleTester.run("no-obj-calls", rule, {
158
245
env : { es2020 : true } ,
159
246
errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "CallExpression" , column : 1 , endColumn : 18 } ]
160
247
} ,
248
+ {
249
+ code : "new globalThis.Math().foo;" ,
250
+ env : { es2020 : true } ,
251
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Math" } , type : "NewExpression" , column : 1 , endColumn : 22 } ]
252
+ } ,
161
253
{
162
254
code : "var x = globalThis.JSON();" ,
163
255
env : { es2020 : true } ,
@@ -181,6 +273,11 @@ ruleTester.run("no-obj-calls", rule, {
181
273
env : { es2020 : true } ,
182
274
errors : [ { messageId : "unexpectedCall" , data : { name : "Reflect" } , type : "CallExpression" } ]
183
275
} ,
276
+ {
277
+ code : "var x = new globalThis.Reflect;" ,
278
+ env : { es2020 : true } ,
279
+ errors : [ { messageId : "unexpectedCall" , data : { name : "Reflect" } , type : "NewExpression" } ]
280
+ } ,
184
281
{
185
282
code : "/*globals Reflect: true*/ Reflect();" ,
186
283
env : { es2020 : true } ,
@@ -195,15 +292,29 @@ ruleTester.run("no-obj-calls", rule, {
195
292
code : "var foo = bar ? baz: JSON; foo();" ,
196
293
errors : [ { messageId : "unexpectedRefCall" , data : { name : "foo" , ref : "JSON" } , type : "CallExpression" } ]
197
294
} ,
295
+ {
296
+ code : "var foo = bar ? baz: JSON; new foo();" ,
297
+ errors : [ { messageId : "unexpectedRefCall" , data : { name : "foo" , ref : "JSON" } , type : "NewExpression" } ]
298
+ } ,
198
299
{
199
300
code : "var foo = bar ? baz: globalThis.JSON; foo();" ,
200
301
env : { es2020 : true } ,
201
302
errors : [ { messageId : "unexpectedRefCall" , data : { name : "foo" , ref : "JSON" } , type : "CallExpression" } ]
202
303
} ,
304
+ {
305
+ code : "var foo = bar ? baz: globalThis.JSON; new foo();" ,
306
+ env : { es2020 : true } ,
307
+ errors : [ { messageId : "unexpectedRefCall" , data : { name : "foo" , ref : "JSON" } , type : "NewExpression" } ]
308
+ } ,
203
309
{
204
310
code : "var foo = window.Atomics; foo();" ,
205
311
env : { es2020 : true , browser : true } ,
206
312
errors : [ { messageId : "unexpectedRefCall" , data : { name : "foo" , ref : "Atomics" } , type : "CallExpression" } ]
313
+ } ,
314
+ {
315
+ code : "var foo = window.Atomics; new foo;" ,
316
+ env : { es2020 : true , browser : true } ,
317
+ errors : [ { messageId : "unexpectedRefCall" , data : { name : "foo" , ref : "Atomics" } , type : "NewExpression" } ]
207
318
}
208
319
]
209
320
} ) ;
0 commit comments