]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/strict.js
e3ea705fe7ef60df0019068d2b48081cd6f1d02b
[pve-eslint.git] / eslint / tests / lib / rules / strict.js
1 /**
2 * @fileoverview Tests for strict rule.
3 * @author Nicholas C. Zakas
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/strict"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("strict", rule, {
22 valid: [
23
24 // "never" mode
25 { code: "foo();", options: ["never"] },
26 { code: "function foo() { return; }", options: ["never"] },
27 { code: "var foo = function() { return; };", options: ["never"] },
28 { code: "foo(); 'use strict';", options: ["never"] },
29 { code: "function foo() { bar(); 'use strict'; return; }", options: ["never"] },
30 { code: "var foo = function() { { 'use strict'; } return; };", options: ["never"] },
31 { code: "(function() { bar('use strict'); return; }());", options: ["never"] },
32 { code: "var fn = x => 1;", options: ["never"], parserOptions: { ecmaVersion: 6 } },
33 { code: "var fn = x => { return; };", options: ["never"], parserOptions: { ecmaVersion: 6 } },
34 { code: "foo();", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } },
35 { code: "function foo() { return; }", options: ["never"], parserOptions: { ecmaFeatures: { impliedStrict: true } } },
36
37 // "global" mode
38 { code: "// Intentionally empty", options: ["global"] },
39 { code: "\"use strict\"; foo();", options: ["global"] },
40 { code: "foo();", options: ["global"], parserOptions: { ecmaVersion: 6, sourceType: "module" } },
41 { code: "function foo() { return; }", options: ["global"], parserOptions: { ecmaFeatures: { impliedStrict: true } } },
42 { code: "'use strict'; function foo() { return; }", options: ["global"] },
43 { code: "'use strict'; var foo = function() { return; };", options: ["global"] },
44 { code: "'use strict'; function foo() { bar(); 'use strict'; return; }", options: ["global"] },
45 { code: "'use strict'; var foo = function() { bar(); 'use strict'; return; };", options: ["global"] },
46 { code: "'use strict'; function foo() { return function() { bar(); 'use strict'; return; }; }", options: ["global"] },
47 { code: "'use strict'; var foo = () => { return () => { bar(); 'use strict'; return; }; }", options: ["global"], parserOptions: { ecmaVersion: 6 } },
48
49 // "function" mode
50 { code: "function foo() { 'use strict'; return; }", options: ["function"] },
51 { code: "function foo() { return; }", options: ["function"], parserOptions: { ecmaVersion: 6, sourceType: "module" } },
52 { code: "function foo() { return; }", options: ["function"], parserOptions: { ecmaFeatures: { impliedStrict: true } } },
53 { code: "var foo = function() { return; }", options: ["function"], parserOptions: { ecmaVersion: 6, sourceType: "module" } },
54 { code: "var foo = function() { 'use strict'; return; }", options: ["function"] },
55 { code: "function foo() { 'use strict'; return; } var bar = function() { 'use strict'; bar(); };", options: ["function"] },
56 { code: "var foo = function() { 'use strict'; function bar() { return; } bar(); };", options: ["function"] },
57 { code: "var foo = () => { 'use strict'; var bar = () => 1; bar(); };", options: ["function"], parserOptions: { ecmaVersion: 6 } },
58 { code: "var foo = () => { var bar = () => 1; bar(); };", options: ["function"], parserOptions: { ecmaVersion: 6, sourceType: "module" } },
59 {
60 code: "class A { constructor() { } }",
61 options: ["function"],
62 parserOptions: { ecmaVersion: 6 }
63 },
64 {
65 code: "class A { foo() { } }",
66 options: ["function"],
67 parserOptions: { ecmaVersion: 6 }
68 },
69 {
70 code: "class A { foo() { function bar() { } } }",
71 options: ["function"],
72 parserOptions: { ecmaVersion: 6 }
73 },
74 {
75 code: "(function() { 'use strict'; function foo(a = 0) { } }())",
76 options: ["function"],
77 parserOptions: { ecmaVersion: 6 }
78 },
79
80
81 // "safe" mode corresponds to "global" if ecmaFeatures.globalReturn is true, otherwise "function"
82 { code: "function foo() { 'use strict'; return; }", options: ["safe"] },
83 { code: "'use strict'; function foo() { return; }", options: ["safe"], parserOptions: { ecmaFeatures: { globalReturn: true } } },
84 { code: "function foo() { return; }", options: ["safe"], parserOptions: { ecmaVersion: 6, sourceType: "module" } },
85 { code: "function foo() { return; }", options: ["safe"], parserOptions: { ecmaFeatures: { impliedStrict: true } } },
86
87 // defaults to "safe" mode
88 "function foo() { 'use strict'; return; }",
89 { code: "'use strict'; function foo() { return; }", parserOptions: { ecmaFeatures: { globalReturn: true } } },
90 { code: "function foo() { return; }", parserOptions: { ecmaVersion: 6, sourceType: "module" } },
91 { code: "function foo() { return; }", parserOptions: { ecmaFeatures: { impliedStrict: true } } },
92
93 // class static blocks do not have directive prologues, therefore this rule should never require od disallow "use strict" statement in them.
94 { code: "'use strict'; class C { static { foo; } }", options: ["global"], parserOptions: { ecmaVersion: 2022 } },
95 { code: "'use strict'; class C { static { 'use strict'; } }", options: ["global"], parserOptions: { ecmaVersion: 2022 } },
96 { code: "'use strict'; class C { static { 'use strict'; 'use strict'; } }", options: ["global"], parserOptions: { ecmaVersion: 2022 } },
97 { code: "class C { static { foo; } }", options: ["function"], parserOptions: { ecmaVersion: 2022 } },
98 { code: "class C { static { 'use strict'; } }", options: ["function"], parserOptions: { ecmaVersion: 2022 } },
99 { code: "class C { static { 'use strict'; 'use strict'; } }", options: ["function"], parserOptions: { ecmaVersion: 2022 } },
100 { code: "class C { static { foo; } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } },
101 { code: "class C { static { 'use strict'; } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } },
102 { code: "class C { static { 'use strict'; 'use strict'; } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } },
103 { code: "class C { static { 'use strict'; } }", options: ["safe"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } },
104 { code: "class C { static { 'use strict'; } }", options: ["safe"], parserOptions: { ecmaVersion: 2022, ecmaFeatures: { impliedStrict: true } } }
105
106 ],
107 invalid: [
108
109 // "never" mode
110 {
111 code: "\"use strict\"; foo();",
112 output: null,
113 options: ["never"],
114 errors: [
115 { messageId: "never", type: "ExpressionStatement" }
116 ]
117 }, {
118 code: "function foo() { 'use strict'; return; }",
119 output: null,
120 options: ["never"],
121 errors: [
122 { messageId: "never", type: "ExpressionStatement" }
123 ]
124 }, {
125 code: "var foo = function() { 'use strict'; return; };",
126 output: null,
127 options: ["never"],
128 errors: [
129 { messageId: "never", type: "ExpressionStatement" }
130 ]
131 }, {
132 code: "function foo() { return function() { 'use strict'; return; }; }",
133 output: null,
134 options: ["never"],
135 errors: [
136 { messageId: "never", type: "ExpressionStatement" }
137 ]
138 }, {
139 code: "'use strict'; function foo() { \"use strict\"; return; }",
140 output: null,
141 options: ["never"],
142 errors: [
143 { messageId: "never", type: "ExpressionStatement" },
144 { messageId: "never", type: "ExpressionStatement" }
145 ]
146 }, {
147 code: "\"use strict\"; foo();",
148 output: " foo();",
149 options: ["never"],
150 parserOptions: { ecmaVersion: 6, sourceType: "module" },
151 errors: [
152 { messageId: "module", type: "ExpressionStatement" }
153 ]
154 }, {
155 code: "'use strict'; function foo() { 'use strict'; return; }",
156 output: " function foo() { return; }",
157 options: ["never"],
158 parserOptions: { ecmaFeatures: { impliedStrict: true } },
159 errors: [
160 { messageId: "implied", type: "ExpressionStatement" },
161 { messageId: "implied", type: "ExpressionStatement" }
162 ]
163 }, {
164 code: "'use strict'; function foo() { 'use strict'; return; }",
165 output: " function foo() { return; }",
166 options: ["never"],
167 parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } },
168 errors: [
169 { messageId: "module", type: "ExpressionStatement" },
170 { messageId: "module", type: "ExpressionStatement" }
171 ]
172 },
173
174 // "global" mode
175 {
176 code: "foo();",
177 output: null,
178 options: ["global"],
179 errors: [
180 { messageId: "global", type: "Program" }
181 ]
182 }, {
183 code: "function foo() { 'use strict'; return; }",
184 output: null,
185 options: ["global"],
186 errors: [
187 { messageId: "global", type: "Program" },
188 { messageId: "global", type: "ExpressionStatement" }
189 ]
190 }, {
191 code: "var foo = function() { 'use strict'; return; }",
192 output: null,
193 options: ["global"],
194 errors: [
195 { messageId: "global", type: "Program" },
196 { messageId: "global", type: "ExpressionStatement" }
197 ]
198 }, {
199 code: "var foo = () => { 'use strict'; return () => 1; }",
200 output: null,
201 options: ["global"],
202 parserOptions: { ecmaVersion: 6 },
203 errors: [
204 { messageId: "global", type: "Program" },
205 { messageId: "global", type: "ExpressionStatement" }
206 ]
207 }, {
208 code: "'use strict'; function foo() { 'use strict'; return; }",
209 output: null,
210 options: ["global"],
211 errors: [
212 { messageId: "global", type: "ExpressionStatement" }
213 ]
214 }, {
215 code: "'use strict'; var foo = function() { 'use strict'; return; };",
216 output: null,
217 options: ["global"],
218 errors: [
219 { messageId: "global", type: "ExpressionStatement" }
220 ]
221 }, {
222 code: "'use strict'; 'use strict'; foo();",
223 output: "'use strict'; foo();",
224 options: ["global"],
225 errors: [
226 { messageId: "multiple", type: "ExpressionStatement" }
227 ]
228 }, {
229 code: "'use strict'; foo();",
230 output: " foo();",
231 options: ["global"],
232 parserOptions: { ecmaVersion: 6, sourceType: "module" },
233 errors: [
234 { messageId: "module", type: "ExpressionStatement" }
235 ]
236 }, {
237 code: "'use strict'; function foo() { 'use strict'; return; }",
238 output: " function foo() { return; }",
239 options: ["global"],
240 parserOptions: { ecmaFeatures: { impliedStrict: true } },
241 errors: [
242 { messageId: "implied", type: "ExpressionStatement" },
243 { messageId: "implied", type: "ExpressionStatement" }
244 ]
245 }, {
246 code: "'use strict'; function foo() { 'use strict'; return; }",
247 output: " function foo() { return; }",
248 options: ["global"],
249 parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } },
250 errors: [
251 { messageId: "module", type: "ExpressionStatement" },
252 { messageId: "module", type: "ExpressionStatement" }
253 ]
254 },
255
256 // "function" mode
257 {
258 code: "'use strict'; foo();",
259 output: null,
260 options: ["function"],
261 errors: [
262 { messageId: "function", type: "ExpressionStatement" }
263 ]
264 }, {
265 code: "'use strict'; (function() { 'use strict'; return true; }());",
266 output: null,
267 options: ["function"],
268 errors: [
269 { messageId: "function", type: "ExpressionStatement" }
270 ]
271 }, {
272 code: "(function() { 'use strict'; function f() { 'use strict'; return } return true; }());",
273 output: "(function() { 'use strict'; function f() { return } return true; }());",
274 options: ["function"],
275 errors: [
276 { messageId: "unnecessary", type: "ExpressionStatement" }
277 ]
278 }, {
279 code: "(function() { return true; }());",
280 output: null,
281 options: ["function"],
282 errors: [
283 { messageId: "function", type: "FunctionExpression" }
284 ]
285 }, {
286 code: "(() => { return true; })();",
287 output: null,
288 options: ["function"],
289 parserOptions: { ecmaVersion: 6 },
290 errors: [
291 { messageId: "function", type: "ArrowFunctionExpression" }
292 ]
293 }, {
294 code: "(() => true)();",
295 output: null,
296 options: ["function"],
297 parserOptions: { ecmaVersion: 6 },
298 errors: [
299 { messageId: "function", type: "ArrowFunctionExpression" }
300 ]
301 }, {
302 code: "var foo = function() { foo(); 'use strict'; return; }; function bar() { foo(); 'use strict'; }",
303 output: null,
304 options: ["function"],
305 errors: [
306 { messageId: "function", type: "FunctionExpression" },
307 { messageId: "function", type: "FunctionDeclaration" }
308 ]
309 }, {
310 code: "function foo() { 'use strict'; 'use strict'; return; }",
311 output: "function foo() { 'use strict'; return; }",
312 options: ["function"],
313 errors: [
314 { messageId: "multiple", type: "ExpressionStatement" }
315 ]
316 }, {
317 code: "var foo = function() { 'use strict'; 'use strict'; return; }",
318 output: "var foo = function() { 'use strict'; return; }",
319 options: ["function"],
320 errors: [
321 { messageId: "multiple", type: "ExpressionStatement" }
322 ]
323 }, {
324 code: "var foo = function() { 'use strict'; return; }",
325 output: "var foo = function() { return; }",
326 options: ["function"],
327 parserOptions: { ecmaVersion: 6, sourceType: "module" },
328 errors: [
329 { messageId: "module", type: "ExpressionStatement" }
330 ]
331 }, {
332 code: "'use strict'; function foo() { 'use strict'; return; }",
333 output: " function foo() { return; }",
334 options: ["function"],
335 parserOptions: { ecmaFeatures: { impliedStrict: true } },
336 errors: [
337 { messageId: "implied", type: "ExpressionStatement" },
338 { messageId: "implied", type: "ExpressionStatement" }
339 ]
340 }, {
341 code: "'use strict'; function foo() { 'use strict'; return; }",
342 output: " function foo() { return; }",
343 options: ["function"],
344 parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } },
345 errors: [
346 { messageId: "module", type: "ExpressionStatement" },
347 { messageId: "module", type: "ExpressionStatement" }
348 ]
349 }, {
350 code: "function foo() { return function() { 'use strict'; return; }; }",
351 output: null,
352 options: ["function"],
353 errors: [
354 { messageId: "function", type: "FunctionDeclaration" }
355 ]
356 }, {
357 code: "var foo = function() { function bar() { 'use strict'; return; } return; }",
358 output: null,
359 options: ["function"],
360 errors: [
361 { messageId: "function", type: "FunctionExpression" }
362 ]
363 }, {
364 code: "function foo() { 'use strict'; return; } var bar = function() { return; };",
365 output: null,
366 options: ["function"],
367 errors: [
368 { messageId: "function", type: "FunctionExpression" }
369 ]
370 }, {
371 code: "var foo = function() { 'use strict'; return; }; function bar() { return; };",
372 output: null,
373 options: ["function"],
374 errors: [
375 { messageId: "function", type: "FunctionDeclaration" }
376 ]
377 }, {
378 code: "function foo() { 'use strict'; return function() { 'use strict'; 'use strict'; return; }; }",
379 output: "function foo() { 'use strict'; return function() { return; }; }",
380 options: ["function"],
381 errors: [
382 { messageId: "unnecessary", type: "ExpressionStatement" },
383 { messageId: "multiple", type: "ExpressionStatement" }
384 ]
385 }, {
386 code: "var foo = function() { 'use strict'; function bar() { 'use strict'; 'use strict'; return; } }",
387 output: "var foo = function() { 'use strict'; function bar() { return; } }",
388 options: ["function"],
389 errors: [
390 { messageId: "unnecessary", type: "ExpressionStatement" },
391 { messageId: "multiple", type: "ExpressionStatement" }
392 ]
393 },
394 {
395 code: "var foo = () => { return; };",
396 output: null,
397 options: ["function"],
398 parserOptions: { ecmaVersion: 6 },
399 errors: [{ messageId: "function", type: "ArrowFunctionExpression" }]
400 },
401
402 // Classes
403 {
404 code: "class A { constructor() { \"use strict\"; } }",
405 output: "class A { constructor() { } }",
406 options: ["function"],
407 parserOptions: { ecmaVersion: 6 },
408 errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }]
409 },
410 {
411 code: "class A { foo() { \"use strict\"; } }",
412 output: "class A { foo() { } }",
413 options: ["function"],
414 parserOptions: { ecmaVersion: 6 },
415 errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }]
416 },
417 {
418 code: "class A { foo() { function bar() { \"use strict\"; } } }",
419 output: "class A { foo() { function bar() { } } }",
420 options: ["function"],
421 parserOptions: { ecmaVersion: 6 },
422 errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }]
423 },
424 {
425 code: "class A { field = () => { \"use strict\"; } }",
426 output: "class A { field = () => { } }",
427 options: ["function"],
428 parserOptions: { ecmaVersion: 2022 },
429 errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }]
430 },
431 {
432 code: "class A { field = function() { \"use strict\"; } }",
433 output: "class A { field = function() { } }",
434 options: ["function"],
435 parserOptions: { ecmaVersion: 2022 },
436 errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }]
437 },
438
439 // "safe" mode corresponds to "global" if ecmaFeatures.globalReturn is true, otherwise "function"
440 {
441 code: "'use strict'; function foo() { return; }",
442 output: null,
443 options: ["safe"],
444 errors: [
445 { messageId: "function", type: "ExpressionStatement" },
446 { messageId: "function", type: "FunctionDeclaration" }
447 ]
448 },
449 {
450 code: "function foo() { 'use strict'; return; }",
451 output: null,
452 options: ["safe"],
453 parserOptions: { ecmaFeatures: { globalReturn: true } },
454 errors: [
455 { messageId: "global", type: "Program" },
456 { messageId: "global", type: "ExpressionStatement" }
457 ]
458 },
459 {
460 code: "'use strict'; function foo() { 'use strict'; return; }",
461 output: " function foo() { return; }",
462 options: ["safe"],
463 parserOptions: { ecmaFeatures: { impliedStrict: true } },
464 errors: [
465 { messageId: "implied", type: "ExpressionStatement" },
466 { messageId: "implied", type: "ExpressionStatement" }
467 ]
468 },
469 {
470 code: "'use strict'; function foo() { 'use strict'; return; }",
471 output: " function foo() { return; }",
472 options: ["safe"],
473 parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } },
474 errors: [
475 { messageId: "module", type: "ExpressionStatement" },
476 { messageId: "module", type: "ExpressionStatement" }
477 ]
478 },
479
480 // Default to "safe" mode
481 {
482 code: "'use strict'; function foo() { return; }",
483 output: null,
484 errors: [
485 { messageId: "function", type: "ExpressionStatement" },
486 { messageId: "function", type: "FunctionDeclaration" }
487 ]
488 },
489 {
490 code: "function foo() { return; }",
491 output: null,
492 errors: [{ messageId: "function", type: "FunctionDeclaration" }]
493 },
494 {
495 code: "function foo() { 'use strict'; return; }",
496 output: null,
497 parserOptions: { ecmaFeatures: { globalReturn: true } },
498 errors: [
499 { messageId: "global", type: "Program" },
500 { messageId: "global", type: "ExpressionStatement" }
501 ]
502 },
503 {
504 code: "'use strict'; function foo() { 'use strict'; return; }",
505 output: " function foo() { return; }",
506 parserOptions: { ecmaFeatures: { impliedStrict: true } },
507 errors: [
508 { messageId: "implied", type: "ExpressionStatement" },
509 { messageId: "implied", type: "ExpressionStatement" }
510 ]
511 },
512 {
513 code: "'use strict'; function foo() { 'use strict'; return; }",
514 output: " function foo() { return; }",
515 parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } },
516 errors: [
517 { messageId: "module", type: "ExpressionStatement" },
518 { messageId: "module", type: "ExpressionStatement" }
519 ]
520 },
521
522 // Reports deprecated syntax: https://github.com/eslint/eslint/issues/6405
523 {
524 code: "function foo(a = 0) { 'use strict' }",
525 output: null,
526 options: [],
527 parserOptions: { ecmaVersion: 6 },
528 errors: [{ messageId: "nonSimpleParameterList" }]
529 },
530 {
531 code: "(function() { 'use strict'; function foo(a = 0) { 'use strict' } }())",
532 output: null,
533 options: [],
534 parserOptions: { ecmaVersion: 6 },
535 errors: [{ messageId: "nonSimpleParameterList" }]
536 },
537 {
538 code: "function foo(a = 0) { 'use strict' }",
539 output: null,
540 options: [],
541 parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } },
542 errors: [
543 "Use the global form of 'use strict'.",
544 { messageId: "nonSimpleParameterList" }
545 ]
546 },
547 {
548 code: "'use strict'; function foo(a = 0) { 'use strict' }",
549 output: null,
550 options: [],
551 parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } },
552 errors: [{ messageId: "nonSimpleParameterList" }]
553 },
554 {
555 code: "function foo(a = 0) { 'use strict' }",
556 output: null,
557 options: ["never"],
558 parserOptions: { ecmaVersion: 6 },
559 errors: [{ messageId: "nonSimpleParameterList" }]
560 },
561 {
562 code: "function foo(a = 0) { 'use strict' }",
563 output: null,
564 options: ["global"],
565 parserOptions: { ecmaVersion: 6 },
566 errors: [
567 "Use the global form of 'use strict'.",
568 { messageId: "nonSimpleParameterList" }
569 ]
570 },
571 {
572 code: "'use strict'; function foo(a = 0) { 'use strict' }",
573 output: null,
574 options: ["global"],
575 parserOptions: { ecmaVersion: 6 },
576 errors: [{ messageId: "nonSimpleParameterList" }]
577 },
578 {
579 code: "function foo(a = 0) { 'use strict' }",
580 output: null,
581 options: ["function"],
582 parserOptions: { ecmaVersion: 6 },
583 errors: [{ messageId: "nonSimpleParameterList" }]
584 },
585 {
586 code: "(function() { 'use strict'; function foo(a = 0) { 'use strict' } }())",
587 output: null,
588 options: ["function"],
589 parserOptions: { ecmaVersion: 6 },
590 errors: [{ messageId: "nonSimpleParameterList" }]
591 },
592 {
593 code: "function foo(a = 0) { }",
594 output: null,
595 options: ["function"],
596 parserOptions: { ecmaVersion: 6 },
597 errors: [{ messageId: "wrap", data: { name: "function 'foo'" } }]
598 },
599 {
600 code: "(function() { function foo(a = 0) { } }())",
601 output: null,
602 options: ["function"],
603 parserOptions: { ecmaVersion: 6 },
604 errors: ["Use the function form of 'use strict'."]
605 },
606
607 // functions inside class static blocks should be checked
608 {
609 code: "'use strict'; class C { static { function foo() { \n'use strict'; } } }",
610 output: null,
611 options: ["global"],
612 parserOptions: { ecmaVersion: 2022 },
613 errors: [{ messageId: "global", line: 2 }]
614 },
615 {
616 code: "class C { static { function foo() { \n'use strict'; } } }",
617 output: null,
618 options: ["never"],
619 parserOptions: { ecmaVersion: 2022 },
620 errors: [{ messageId: "never", line: 2 }]
621 },
622 {
623 code: "class C { static { function foo() { \n'use strict'; } } }",
624 output: "class C { static { function foo() { \n } } }",
625 options: ["safe"],
626 parserOptions: { ecmaVersion: 2022, sourceType: "module" },
627 errors: [{ messageId: "module", line: 2 }]
628 },
629 {
630 code: "class C { static { function foo() { \n'use strict'; } } }",
631 output: "class C { static { function foo() { \n } } }",
632 options: ["safe"],
633 parserOptions: { ecmaVersion: 2022, ecmaFeatures: { impliedStrict: true } },
634 errors: [{ messageId: "implied", line: 2 }]
635 },
636 {
637 code: "function foo() {'use strict'; class C { static { function foo() { \n'use strict'; } } } }",
638 output: "function foo() {'use strict'; class C { static { function foo() { \n } } } }",
639 options: ["function"],
640 parserOptions: { ecmaVersion: 2022 },
641 errors: [{ messageId: "unnecessary", line: 2 }]
642 },
643 {
644 code: "class C { static { function foo() { \n'use strict'; } } }",
645 output: "class C { static { function foo() { \n } } }",
646 options: ["function"],
647 parserOptions: { ecmaVersion: 2022 },
648 errors: [{ messageId: "unnecessaryInClasses", line: 2 }]
649 },
650 {
651 code: "class C { static { function foo() { \n'use strict';\n'use strict'; } } }",
652 output: "class C { static { function foo() { \n\n } } }",
653 options: ["function"],
654 parserOptions: { ecmaVersion: 2022 },
655 errors: [
656 { messageId: "unnecessaryInClasses", line: 2 },
657 { messageId: "multiple", line: 3 }
658 ]
659 }
660 ]
661 });