]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/camelcase.js
import 7.12.1 upstream release
[pve-eslint.git] / eslint / tests / lib / rules / camelcase.js
1 /**
2 * @fileoverview Tests for camelcase rule.
3 * @author Nicholas C. Zakas
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/camelcase"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("camelcase", rule, {
22 valid: [
23 "firstName = \"Nicholas\"",
24 "FIRST_NAME = \"Nicholas\"",
25 "__myPrivateVariable = \"Patrick\"",
26 "myPrivateVariable_ = \"Patrick\"",
27 "function doSomething(){}",
28 "do_something()",
29 "new do_something",
30 "new do_something()",
31 "foo.do_something()",
32 "var foo = bar.baz_boom;",
33 "var foo = bar.baz_boom.something;",
34 "foo.boom_pow.qux = bar.baz_boom.something;",
35 "if (bar.baz_boom) {}",
36 "var obj = { key: foo.bar_baz };",
37 "var arr = [foo.bar_baz];",
38 "[foo.bar_baz]",
39 "var arr = [foo.bar_baz.qux];",
40 "[foo.bar_baz.nesting]",
41 "if (foo.bar_baz === boom.bam_pow) { [foo.baz_boom] }",
42 {
43 code: "var o = {key: 1}",
44 options: [{ properties: "always" }]
45 },
46 {
47 code: "var o = {_leading: 1}",
48 options: [{ properties: "always" }]
49 },
50 {
51 code: "var o = {trailing_: 1}",
52 options: [{ properties: "always" }]
53 },
54 {
55 code: "var o = {bar_baz: 1}",
56 options: [{ properties: "never" }]
57 },
58 {
59 code: "var o = {_leading: 1}",
60 options: [{ properties: "never" }]
61 },
62 {
63 code: "var o = {trailing_: 1}",
64 options: [{ properties: "never" }]
65 },
66 {
67 code: "obj.a_b = 2;",
68 options: [{ properties: "never" }]
69 },
70 {
71 code: "obj._a = 2;",
72 options: [{ properties: "always" }]
73 },
74 {
75 code: "obj.a_ = 2;",
76 options: [{ properties: "always" }]
77 },
78 {
79 code: "obj._a = 2;",
80 options: [{ properties: "never" }]
81 },
82 {
83 code: "obj.a_ = 2;",
84 options: [{ properties: "never" }]
85 },
86 {
87 code: "var obj = {\n a_a: 1 \n};\n obj.a_b = 2;",
88 options: [{ properties: "never" }]
89 },
90 {
91 code: "obj.foo_bar = function(){};",
92 options: [{ properties: "never" }]
93 },
94 {
95 code: "const { ['foo']: _foo } = obj;",
96 parserOptions: { ecmaVersion: 6 }
97 },
98 {
99 code: "const { [_foo_]: foo } = obj;",
100 parserOptions: { ecmaVersion: 6 }
101 },
102 {
103 code: "var { category_id } = query;",
104 options: [{ ignoreDestructuring: true }],
105 parserOptions: { ecmaVersion: 6 }
106 },
107 {
108 code: "var { category_id: category_id } = query;",
109 options: [{ ignoreDestructuring: true }],
110 parserOptions: { ecmaVersion: 6 }
111 },
112 {
113 code: "var { category_id = 1 } = query;",
114 options: [{ ignoreDestructuring: true }],
115 parserOptions: { ecmaVersion: 6 }
116 },
117 {
118 code: "var { [{category_id} = query]: categoryId } = query;",
119 options: [{ ignoreDestructuring: true }],
120 parserOptions: { ecmaVersion: 6 }
121 },
122 {
123 code: "var { category_id: category } = query;",
124 parserOptions: { ecmaVersion: 6 }
125 },
126 {
127 code: "var { _leading } = query;",
128 parserOptions: { ecmaVersion: 6 }
129 },
130 {
131 code: "var { trailing_ } = query;",
132 parserOptions: { ecmaVersion: 6 }
133 },
134 {
135 code: "import { camelCased } from \"external module\";",
136 parserOptions: { ecmaVersion: 6, sourceType: "module" }
137 },
138 {
139 code: "import { _leading } from \"external module\";",
140 parserOptions: { ecmaVersion: 6, sourceType: "module" }
141 },
142 {
143 code: "import { trailing_ } from \"external module\";",
144 parserOptions: { ecmaVersion: 6, sourceType: "module" }
145 },
146 {
147 code: "import { no_camelcased as camelCased } from \"external-module\";",
148 parserOptions: { ecmaVersion: 6, sourceType: "module" }
149 },
150 {
151 code: "import { no_camelcased as _leading } from \"external-module\";",
152 parserOptions: { ecmaVersion: 6, sourceType: "module" }
153 },
154 {
155 code: "import { no_camelcased as trailing_ } from \"external-module\";",
156 parserOptions: { ecmaVersion: 6, sourceType: "module" }
157 },
158 {
159 code: "import { no_camelcased as camelCased, anotherCamelCased } from \"external-module\";",
160 parserOptions: { ecmaVersion: 6, sourceType: "module" }
161 },
162 {
163 code: "import { snake_cased } from 'mod'",
164 options: [{ ignoreImports: true }],
165 parserOptions: { ecmaVersion: 6, sourceType: "module" }
166 },
167 {
168 code: "import { camelCased } from 'mod'",
169 options: [{ ignoreImports: false }],
170 parserOptions: { ecmaVersion: 6, sourceType: "module" }
171 },
172 {
173 code: "var _camelCased = aGlobalVariable",
174 options: [{ ignoreGlobals: false }],
175 globals: { aGlobalVariable: "readonly" }
176 },
177 {
178 code: "var camelCased = _aGlobalVariable",
179 options: [{ ignoreGlobals: false }],
180 globals: { _aGlobalVariable: "readonly" }
181 },
182 {
183 code: "var camelCased = a_global_variable",
184 options: [{ ignoreGlobals: true }],
185 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase
186 },
187 {
188 code: "a_global_variable.foo()",
189 options: [{ ignoreGlobals: true }],
190 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase
191 },
192 {
193 code: "a_global_variable[undefined]",
194 options: [{ ignoreGlobals: true }],
195 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase
196 },
197 {
198 code: "var foo = a_global_variable.bar",
199 options: [{ ignoreGlobals: true }],
200 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase
201 },
202 {
203 code: "a_global_variable.foo = bar",
204 options: [{ ignoreGlobals: true }],
205 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase
206 },
207 {
208 code: "( { foo: a_global_variable.bar } = baz )",
209 options: [{ ignoreGlobals: true }],
210 parserOptions: { ecmaVersion: 6 },
211 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase
212 },
213 {
214 code: "a_global_variable = foo",
215 options: [{ ignoreGlobals: true }],
216 globals: { a_global_variable: "writable" } // eslint-disable-line camelcase
217 },
218 {
219 code: "a_global_variable = foo",
220 options: [{ ignoreGlobals: true }],
221 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase
222 },
223 {
224 code: "({ a_global_variable } = foo)",
225 options: [{ ignoreGlobals: true }],
226 parserOptions: { ecmaVersion: 6 },
227 globals: { a_global_variable: "writable" } // eslint-disable-line camelcase
228 },
229 {
230 code: "({ snake_cased: a_global_variable } = foo)",
231 options: [{ ignoreGlobals: true }],
232 parserOptions: { ecmaVersion: 6 },
233 globals: { a_global_variable: "writable" } // eslint-disable-line camelcase
234 },
235 {
236 code: "({ snake_cased: a_global_variable = foo } = bar)",
237 options: [{ ignoreGlobals: true }],
238 parserOptions: { ecmaVersion: 6 },
239 globals: { a_global_variable: "writable" } // eslint-disable-line camelcase
240 },
241 {
242 code: "[a_global_variable] = bar",
243 options: [{ ignoreGlobals: true }],
244 parserOptions: { ecmaVersion: 6 },
245 globals: { a_global_variable: "writable" } // eslint-disable-line camelcase
246 },
247 {
248 code: "[a_global_variable = foo] = bar",
249 options: [{ ignoreGlobals: true }],
250 parserOptions: { ecmaVersion: 6 },
251 globals: { a_global_variable: "writable" } // eslint-disable-line camelcase
252 },
253 {
254 code: "foo[a_global_variable] = bar",
255 options: [{ ignoreGlobals: true }],
256 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase
257 },
258 {
259 code: "var foo = { [a_global_variable]: bar }",
260 options: [{ ignoreGlobals: true }],
261 parserOptions: { ecmaVersion: 6 },
262 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase
263 },
264 {
265 code: "var { [a_global_variable]: foo } = bar",
266 options: [{ ignoreGlobals: true }],
267 parserOptions: { ecmaVersion: 6 },
268 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase
269 },
270 {
271 code: "function foo({ no_camelcased: camelCased }) {};",
272 parserOptions: { ecmaVersion: 6 }
273 },
274 {
275 code: "function foo({ no_camelcased: _leading }) {};",
276 parserOptions: { ecmaVersion: 6 }
277 },
278 {
279 code: "function foo({ no_camelcased: trailing_ }) {};",
280 parserOptions: { ecmaVersion: 6 }
281 },
282 {
283 code: "function foo({ camelCased = 'default value' }) {};",
284 parserOptions: { ecmaVersion: 6 }
285 },
286 {
287 code: "function foo({ _leading = 'default value' }) {};",
288 parserOptions: { ecmaVersion: 6 }
289 },
290 {
291 code: "function foo({ trailing_ = 'default value' }) {};",
292 parserOptions: { ecmaVersion: 6 }
293 },
294 {
295 code: "function foo({ camelCased }) {};",
296 parserOptions: { ecmaVersion: 6 }
297 },
298 {
299 code: "function foo({ _leading }) {}",
300 parserOptions: { ecmaVersion: 6 }
301 },
302 {
303 code: "function foo({ trailing_ }) {}",
304 parserOptions: { ecmaVersion: 6 }
305 },
306 {
307 code: "ignored_foo = 0;",
308 options: [{ allow: ["ignored_foo"] }]
309 },
310 {
311 code: "ignored_foo = 0; ignored_bar = 1;",
312 options: [{ allow: ["ignored_foo", "ignored_bar"] }]
313 },
314 {
315 code: "user_id = 0;",
316 options: [{ allow: ["_id$"] }]
317 },
318 {
319 code: "__option_foo__ = 0;",
320 options: [{ allow: ["__option_foo__"] }]
321 },
322 {
323 code: "foo = { [computedBar]: 0 };",
324 options: [{ ignoreDestructuring: true }],
325 parserOptions: { ecmaVersion: 6 }
326 },
327 {
328 code: "({ a: obj.fo_o } = bar);",
329 options: [{ allow: ["fo_o"] }],
330 parserOptions: { ecmaVersion: 6 }
331 },
332 {
333 code: "({ a: obj.foo } = bar);",
334 options: [{ allow: ["fo_o"] }],
335 parserOptions: { ecmaVersion: 6 }
336 },
337 {
338 code: "({ a: obj.fo_o } = bar);",
339 options: [{ properties: "never" }],
340 parserOptions: { ecmaVersion: 6 }
341 },
342 {
343 code: "({ a: obj.fo_o.b_ar } = bar);",
344 options: [{ properties: "never" }],
345 parserOptions: { ecmaVersion: 6 }
346 },
347 {
348 code: "({ a: { b: obj.fo_o } } = bar);",
349 options: [{ properties: "never" }],
350 parserOptions: { ecmaVersion: 6 }
351 },
352 {
353 code: "([obj.fo_o] = bar);",
354 options: [{ properties: "never" }],
355 parserOptions: { ecmaVersion: 6 }
356 },
357 {
358 code: "({ c: [ob.fo_o]} = bar);",
359 options: [{ properties: "never" }],
360 parserOptions: { ecmaVersion: 6 }
361 },
362 {
363 code: "([obj.fo_o.b_ar] = bar);",
364 options: [{ properties: "never" }],
365 parserOptions: { ecmaVersion: 6 }
366 },
367 {
368 code: "({obj} = baz.fo_o);",
369 parserOptions: { ecmaVersion: 6 }
370 },
371 {
372 code: "([obj] = baz.fo_o);",
373 parserOptions: { ecmaVersion: 6 }
374 },
375 {
376 code: "([obj.foo = obj.fo_o] = bar);",
377 options: [{ properties: "always" }],
378 parserOptions: { ecmaVersion: 6 }
379 }
380 ],
381 invalid: [
382 {
383 code: "first_name = \"Nicholas\"",
384 errors: [
385 {
386 messageId: "notCamelCase",
387 data: { name: "first_name" },
388 type: "Identifier"
389 }
390 ]
391 },
392 {
393 code: "__private_first_name = \"Patrick\"",
394 errors: [
395 {
396 messageId: "notCamelCase",
397 data: { name: "__private_first_name" },
398 type: "Identifier"
399 }
400 ]
401 },
402 {
403 code: "function foo_bar(){}",
404 errors: [
405 {
406 messageId: "notCamelCase",
407 data: { name: "foo_bar" },
408 type: "Identifier"
409 }
410 ]
411 },
412 {
413 code: "obj.foo_bar = function(){};",
414 errors: [
415 {
416 messageId: "notCamelCase",
417 data: { name: "foo_bar" },
418 type: "Identifier"
419 }
420 ]
421 },
422 {
423 code: "bar_baz.foo = function(){};",
424 errors: [
425 {
426 messageId: "notCamelCase",
427 data: { name: "bar_baz" },
428 type: "Identifier"
429 }
430 ]
431 },
432 {
433 code: "[foo_bar.baz]",
434 errors: [
435 {
436 messageId: "notCamelCase",
437 data: { name: "foo_bar" },
438 type: "Identifier"
439 }
440 ]
441 },
442 {
443 code: "if (foo.bar_baz === boom.bam_pow) { [foo_bar.baz] }",
444 errors: [
445 {
446 messageId: "notCamelCase",
447 data: { name: "foo_bar" },
448 type: "Identifier"
449 }
450 ]
451 },
452 {
453 code: "foo.bar_baz = boom.bam_pow",
454 errors: [
455 {
456 messageId: "notCamelCase",
457 data: { name: "bar_baz" },
458 type: "Identifier"
459 }
460 ]
461 },
462 {
463 code: "var foo = { bar_baz: boom.bam_pow }",
464 errors: [
465 {
466 messageId: "notCamelCase",
467 data: { name: "bar_baz" },
468 type: "Identifier"
469 }
470 ]
471 },
472 {
473 code: "var foo = { bar_baz: boom.bam_pow }",
474 options: [{ ignoreDestructuring: true }],
475 errors: [
476 {
477 messageId: "notCamelCase",
478 data: { name: "bar_baz" },
479 type: "Identifier"
480 }
481 ]
482 },
483 {
484 code: "foo.qux.boom_pow = { bar: boom.bam_pow }",
485 errors: [
486 {
487 messageId: "notCamelCase",
488 data: { name: "boom_pow" },
489 type: "Identifier"
490 }
491 ]
492 },
493 {
494 code: "var o = {bar_baz: 1}",
495 options: [{ properties: "always" }],
496 errors: [
497 {
498 messageId: "notCamelCase",
499 data: { name: "bar_baz" },
500 type: "Identifier"
501 }
502 ]
503 },
504 {
505 code: "obj.a_b = 2;",
506 options: [{ properties: "always" }],
507 errors: [
508 {
509 messageId: "notCamelCase",
510 data: { name: "a_b" },
511 type: "Identifier"
512 }
513 ]
514 },
515 {
516 code: "var { category_id: category_alias } = query;",
517 parserOptions: { ecmaVersion: 6 },
518 errors: [
519 {
520 messageId: "notCamelCase",
521 data: { name: "category_alias" },
522 type: "Identifier"
523 }
524 ]
525 },
526 {
527 code: "var { category_id: category_alias } = query;",
528 options: [{ ignoreDestructuring: true }],
529 parserOptions: { ecmaVersion: 6 },
530 errors: [
531 {
532 messageId: "notCamelCase",
533 data: { name: "category_alias" },
534 type: "Identifier"
535 }
536 ]
537 },
538 {
539 code: "var { [category_id]: categoryId } = query;",
540 options: [{ ignoreDestructuring: true }],
541 parserOptions: { ecmaVersion: 6 },
542 errors: [
543 {
544 messageId: "notCamelCase",
545 data: { name: "category_id" },
546 type: "Identifier"
547 }
548 ]
549 },
550 {
551 code: "var { [category_id]: categoryId } = query;",
552 parserOptions: { ecmaVersion: 6 },
553 errors: [
554 {
555 messageId: "notCamelCase",
556 data: { name: "category_id" },
557 type: "Identifier"
558 }
559 ]
560 },
561 {
562 code: "var { category_id: categoryId, ...other_props } = query;",
563 options: [{ ignoreDestructuring: true }],
564 parserOptions: { ecmaVersion: 2018 },
565 errors: [
566 {
567 messageId: "notCamelCase",
568 data: { name: "other_props" },
569 type: "Identifier"
570 }
571 ]
572 },
573 {
574 code: "var { category_id } = query;",
575 parserOptions: { ecmaVersion: 6 },
576 errors: [
577 {
578 messageId: "notCamelCase",
579 data: { name: "category_id" },
580 type: "Identifier"
581 }
582 ]
583 },
584 {
585 code: "var { category_id: category_id } = query;",
586 parserOptions: { ecmaVersion: 6 },
587 errors: [
588 {
589 messageId: "notCamelCase",
590 data: { name: "category_id" },
591 type: "Identifier"
592 }
593 ]
594 },
595 {
596 code: "var { category_id = 1 } = query;",
597 parserOptions: { ecmaVersion: 6 },
598 errors: [
599 {
600 messageId: "notCamelCase",
601 data: { name: "category_id" },
602 type: "Identifier"
603 }
604 ]
605 },
606 {
607 code: "import no_camelcased from \"external-module\";",
608 parserOptions: { ecmaVersion: 6, sourceType: "module" },
609 errors: [
610 {
611 messageId: "notCamelCase",
612 data: { name: "no_camelcased" },
613 type: "Identifier"
614 }
615 ]
616 },
617 {
618 code: "import * as no_camelcased from \"external-module\";",
619 parserOptions: { ecmaVersion: 6, sourceType: "module" },
620 errors: [
621 {
622 messageId: "notCamelCase",
623 data: { name: "no_camelcased" },
624 type: "Identifier"
625 }
626 ]
627 },
628 {
629 code: "import { no_camelcased } from \"external-module\";",
630 parserOptions: { ecmaVersion: 6, sourceType: "module" },
631 errors: [
632 {
633 messageId: "notCamelCase",
634 data: { name: "no_camelcased" },
635 type: "Identifier"
636 }
637 ]
638 },
639 {
640 code: "import { no_camelcased as no_camel_cased } from \"external module\";",
641 parserOptions: { ecmaVersion: 6, sourceType: "module" },
642 errors: [
643 {
644 messageId: "notCamelCase",
645 data: { name: "no_camel_cased" },
646 type: "Identifier"
647 }
648 ]
649 },
650 {
651 code: "import { camelCased as no_camel_cased } from \"external module\";",
652 parserOptions: { ecmaVersion: 6, sourceType: "module" },
653 errors: [
654 {
655 messageId: "notCamelCase",
656 data: { name: "no_camel_cased" },
657 type: "Identifier"
658 }
659 ]
660 },
661 {
662 code: "import { camelCased, no_camelcased } from \"external-module\";",
663 parserOptions: { ecmaVersion: 6, sourceType: "module" },
664 errors: [
665 {
666 messageId: "notCamelCase",
667 data: { name: "no_camelcased" },
668 type: "Identifier"
669 }
670 ]
671 },
672 {
673 code: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";",
674 parserOptions: { ecmaVersion: 6, sourceType: "module" },
675 errors: [
676 {
677 messageId: "notCamelCase",
678 data: { name: "another_no_camelcased" },
679 type: "Identifier"
680 }
681 ]
682 },
683 {
684 code: "import camelCased, { no_camelcased } from \"external-module\";",
685 parserOptions: { ecmaVersion: 6, sourceType: "module" },
686 errors: [
687 {
688 messageId: "notCamelCase",
689 data: { name: "no_camelcased" },
690 type: "Identifier"
691 }
692 ]
693 },
694 {
695 code: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";",
696 parserOptions: { ecmaVersion: 6, sourceType: "module" },
697 errors: [
698 {
699 messageId: "notCamelCase",
700 data: { name: "no_camelcased" },
701 type: "Identifier"
702 }
703 ]
704 },
705 {
706 code: "import snake_cased from 'mod'",
707 options: [{ ignoreImports: true }],
708 parserOptions: { ecmaVersion: 6, sourceType: "module" },
709 errors: [
710 {
711 messageId: "notCamelCase",
712 data: { name: "snake_cased" },
713 type: "Identifier"
714 }
715 ]
716 },
717 {
718 code: "import * as snake_cased from 'mod'",
719 options: [{ ignoreImports: true }],
720 parserOptions: { ecmaVersion: 6, sourceType: "module" },
721 errors: [
722 {
723 messageId: "notCamelCase",
724 data: { name: "snake_cased" },
725 type: "Identifier"
726 }
727 ]
728 },
729 {
730 code: "import snake_cased from 'mod'",
731 options: [{ ignoreImports: false }],
732 parserOptions: { ecmaVersion: 6, sourceType: "module" },
733 errors: [
734 {
735 messageId: "notCamelCase",
736 data: { name: "snake_cased" },
737 type: "Identifier"
738 }
739 ]
740 },
741 {
742 code: "import * as snake_cased from 'mod'",
743 options: [{ ignoreImports: false }],
744 parserOptions: { ecmaVersion: 6, sourceType: "module" },
745 errors: [
746 {
747 messageId: "notCamelCase",
748 data: { name: "snake_cased" },
749 type: "Identifier"
750 }
751 ]
752 },
753 {
754 code: "var camelCased = snake_cased",
755 options: [{ ignoreGlobals: false }],
756 globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase
757 errors: [
758 {
759 messageId: "notCamelCase",
760 data: { name: "snake_cased" },
761 type: "Identifier"
762 }
763 ]
764 },
765 {
766 code: "a_global_variable.foo()",
767 options: [{ ignoreGlobals: false }],
768 globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase
769 errors: [
770 {
771 messageId: "notCamelCase",
772 data: { name: "a_global_variable" },
773 type: "Identifier"
774 }
775 ]
776 },
777 {
778 code: "a_global_variable[undefined]",
779 options: [{ ignoreGlobals: false }],
780 globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase
781 errors: [
782 {
783 messageId: "notCamelCase",
784 data: { name: "a_global_variable" },
785 type: "Identifier"
786 }
787 ]
788 },
789 {
790 code: "var camelCased = snake_cased",
791 globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase
792 errors: [
793 {
794 messageId: "notCamelCase",
795 data: { name: "snake_cased" },
796 type: "Identifier"
797 }
798 ]
799 },
800 {
801 code: "var camelCased = snake_cased",
802 options: [{}],
803 globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase
804 errors: [
805 {
806 messageId: "notCamelCase",
807 data: { name: "snake_cased" },
808 type: "Identifier"
809 }
810 ]
811 },
812 {
813 code: "foo.a_global_variable = bar",
814 options: [{ ignoreGlobals: true }],
815 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase
816 errors: [
817 {
818 messageId: "notCamelCase",
819 data: { name: "a_global_variable" },
820 type: "Identifier"
821 }
822 ]
823 },
824 {
825 code: "var foo = { a_global_variable: bar }",
826 options: [{ ignoreGlobals: true }],
827 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase
828 errors: [
829 {
830 messageId: "notCamelCase",
831 data: { name: "a_global_variable" },
832 type: "Identifier"
833 }
834 ]
835 },
836 {
837 code: "var foo = { a_global_variable: a_global_variable }",
838 options: [{ ignoreGlobals: true }],
839 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase
840 errors: [
841 {
842 messageId: "notCamelCase",
843 data: { name: "a_global_variable" },
844 type: "Identifier",
845 column: 13
846 }
847 ]
848 },
849 {
850 code: "var foo = { a_global_variable() {} }",
851 options: [{ ignoreGlobals: true }],
852 parserOptions: { ecmaVersion: 6 },
853 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase
854 errors: [
855 {
856 messageId: "notCamelCase",
857 data: { name: "a_global_variable" },
858 type: "Identifier"
859 }
860 ]
861 },
862 {
863 code: "class Foo { a_global_variable() {} }",
864 options: [{ ignoreGlobals: true }],
865 parserOptions: { ecmaVersion: 6 },
866 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase
867 errors: [
868 {
869 messageId: "notCamelCase",
870 data: { name: "a_global_variable" },
871 type: "Identifier"
872 }
873 ]
874 },
875 {
876 code: "a_global_variable: for (;;);",
877 options: [{ ignoreGlobals: true }],
878 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase
879 errors: [
880 {
881 messageId: "notCamelCase",
882 data: { name: "a_global_variable" },
883 type: "Identifier"
884 }
885 ]
886 },
887 {
888 code: "if (foo) { let a_global_variable; a_global_variable = bar; }",
889 options: [{ ignoreGlobals: true }],
890 parserOptions: { ecmaVersion: 6 },
891 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase
892 errors: [
893 {
894 messageId: "notCamelCase",
895 data: { name: "a_global_variable" },
896 type: "Identifier",
897 column: 16
898 },
899 {
900 messageId: "notCamelCase",
901 data: { name: "a_global_variable" },
902 type: "Identifier",
903 column: 35
904 }
905 ]
906 },
907 {
908 code: "function foo(a_global_variable) { foo = a_global_variable; }",
909 options: [{ ignoreGlobals: true }],
910 parserOptions: { ecmaVersion: 6 },
911 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase
912 errors: [
913 {
914 messageId: "notCamelCase",
915 data: { name: "a_global_variable" },
916 type: "Identifier",
917 column: 14
918 },
919 {
920 messageId: "notCamelCase",
921 data: { name: "a_global_variable" },
922 type: "Identifier",
923 column: 41
924 }
925 ]
926 },
927 {
928 code: "var a_global_variable",
929 options: [{ ignoreGlobals: true }],
930 parserOptions: { ecmaVersion: 6 },
931 errors: [
932 {
933 messageId: "notCamelCase",
934 data: { name: "a_global_variable" },
935 type: "Identifier"
936 }
937 ]
938 },
939 {
940 code: "function a_global_variable () {}",
941 options: [{ ignoreGlobals: true }],
942 parserOptions: { ecmaVersion: 6 },
943 errors: [
944 {
945 messageId: "notCamelCase",
946 data: { name: "a_global_variable" },
947 type: "Identifier"
948 }
949 ]
950 },
951 {
952 code: "const a_global_variable = foo; bar = a_global_variable",
953 options: [{ ignoreGlobals: true }],
954 parserOptions: { ecmaVersion: 6 },
955 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase
956 errors: [
957 {
958 messageId: "notCamelCase",
959 data: { name: "a_global_variable" },
960 type: "Identifier",
961 column: 7
962 },
963 {
964 messageId: "notCamelCase",
965 data: { name: "a_global_variable" },
966 type: "Identifier",
967 column: 38
968 }
969 ]
970 },
971 {
972 code: "bar = a_global_variable; var a_global_variable;",
973 options: [{ ignoreGlobals: true }],
974 parserOptions: { ecmaVersion: 6 },
975 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase
976 errors: [
977 {
978 messageId: "notCamelCase",
979 data: { name: "a_global_variable" },
980 type: "Identifier",
981 column: 7
982 },
983 {
984 messageId: "notCamelCase",
985 data: { name: "a_global_variable" },
986 type: "Identifier",
987 column: 30
988 }
989 ]
990 },
991 {
992 code: "var foo = { a_global_variable }",
993 options: [{ ignoreGlobals: true }],
994 parserOptions: { ecmaVersion: 6 },
995 globals: { a_global_variable: "readonly" }, // eslint-disable-line camelcase
996 errors: [
997 {
998 messageId: "notCamelCase",
999 data: { name: "a_global_variable" },
1000 type: "Identifier"
1001 }
1002 ]
1003 },
1004 {
1005 code: "export * as snake_cased from 'mod'",
1006 parserOptions: { ecmaVersion: 2020, sourceType: "module" },
1007 errors: [
1008 {
1009 messageId: "notCamelCase",
1010 data: { name: "snake_cased" },
1011 type: "Identifier"
1012 }
1013 ]
1014 },
1015 {
1016 code: "function foo({ no_camelcased }) {};",
1017 parserOptions: { ecmaVersion: 6 },
1018 errors: [
1019 {
1020 messageId: "notCamelCase",
1021 data: { name: "no_camelcased" },
1022 type: "Identifier"
1023 }
1024 ]
1025 },
1026 {
1027 code: "function foo({ no_camelcased = 'default value' }) {};",
1028 parserOptions: { ecmaVersion: 6 },
1029 errors: [
1030 {
1031 messageId: "notCamelCase",
1032 data: { name: "no_camelcased" },
1033 type: "Identifier"
1034 }
1035 ]
1036 },
1037 {
1038 code: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}",
1039 parserOptions: { ecmaVersion: 6 },
1040 errors: [
1041 {
1042 messageId: "notCamelCase",
1043 data: { name: "no_camelcased" },
1044 type: "Identifier"
1045 },
1046 {
1047 messageId: "notCamelCase",
1048 data: { name: "camelcased_value" },
1049 type: "Identifier"
1050 }
1051 ]
1052 },
1053 {
1054 code: "const { bar: no_camelcased } = foo;",
1055 parserOptions: { ecmaVersion: 6 },
1056 errors: [
1057 {
1058 messageId: "notCamelCase",
1059 data: { name: "no_camelcased" },
1060 type: "Identifier"
1061 }
1062 ]
1063 },
1064 {
1065 code: "function foo({ value_1: my_default }) {}",
1066 parserOptions: { ecmaVersion: 6 },
1067 errors: [
1068 {
1069 messageId: "notCamelCase",
1070 data: { name: "my_default" },
1071 type: "Identifier"
1072 }
1073 ]
1074 },
1075 {
1076 code: "function foo({ isCamelcased: no_camelcased }) {};",
1077 parserOptions: { ecmaVersion: 6 },
1078 errors: [
1079 {
1080 messageId: "notCamelCase",
1081 data: { name: "no_camelcased" },
1082 type: "Identifier"
1083 }
1084 ]
1085 },
1086 {
1087 code: "var { foo: bar_baz = 1 } = quz;",
1088 parserOptions: { ecmaVersion: 6 },
1089 errors: [
1090 {
1091 messageId: "notCamelCase",
1092 data: { name: "bar_baz" },
1093 type: "Identifier"
1094 }
1095 ]
1096 },
1097 {
1098 code: "const { no_camelcased = false } = bar;",
1099 parserOptions: { ecmaVersion: 6 },
1100 errors: [
1101 {
1102 messageId: "notCamelCase",
1103 data: { name: "no_camelcased" },
1104 type: "Identifier"
1105 }
1106 ]
1107 },
1108 {
1109 code: "const { no_camelcased = foo_bar } = bar;",
1110 parserOptions: { ecmaVersion: 6 },
1111 errors: [
1112 {
1113 messageId: "notCamelCase",
1114 data: { name: "no_camelcased" },
1115 type: "Identifier"
1116 }
1117 ]
1118 },
1119 {
1120 code: "not_ignored_foo = 0;",
1121 options: [{ allow: ["ignored_bar"] }],
1122 errors: [
1123 {
1124 messageId: "notCamelCase",
1125 data: { name: "not_ignored_foo" },
1126 type: "Identifier"
1127 }
1128 ]
1129 },
1130 {
1131 code: "not_ignored_foo = 0;",
1132 options: [{ allow: ["_id$"] }],
1133 errors: [
1134 {
1135 messageId: "notCamelCase",
1136 data: { name: "not_ignored_foo" },
1137 type: "Identifier"
1138 }
1139 ]
1140 },
1141 {
1142 code: "foo = { [computed_bar]: 0 };",
1143 options: [{ ignoreDestructuring: true }],
1144 parserOptions: { ecmaVersion: 6 },
1145 errors: [
1146 {
1147 messageId: "notCamelCase",
1148 data: { name: "computed_bar" },
1149 type: "Identifier"
1150 }
1151 ]
1152 },
1153 {
1154 code: "({ a: obj.fo_o } = bar);",
1155 parserOptions: { ecmaVersion: 6 },
1156 errors: [
1157 {
1158 messageId: "notCamelCase",
1159 data: { name: "fo_o" },
1160 type: "Identifier"
1161 }
1162 ]
1163 },
1164 {
1165 code: "({ a: obj.fo_o } = bar);",
1166 options: [{ ignoreDestructuring: true }],
1167 parserOptions: { ecmaVersion: 6 },
1168 errors: [
1169 {
1170 messageId: "notCamelCase",
1171 data: { name: "fo_o" },
1172 type: "Identifier"
1173 }
1174 ]
1175 },
1176 {
1177 code: "({ a: obj.fo_o.b_ar } = baz);",
1178 parserOptions: { ecmaVersion: 6 },
1179 errors: [
1180 {
1181 messageId: "notCamelCase",
1182 data: { name: "b_ar" },
1183 type: "Identifier"
1184 }
1185 ]
1186 },
1187 {
1188 code: "({ a: { b: { c: obj.fo_o } } } = bar);",
1189 parserOptions: { ecmaVersion: 6 },
1190 errors: [
1191 {
1192 messageId: "notCamelCase",
1193 data: { name: "fo_o" },
1194 type: "Identifier"
1195 }
1196 ]
1197 },
1198 {
1199 code: "({ a: { b: { c: obj.fo_o.b_ar } } } = baz);",
1200 parserOptions: { ecmaVersion: 6 },
1201 errors: [
1202 {
1203 messageId: "notCamelCase",
1204 data: { name: "b_ar" },
1205 type: "Identifier"
1206 }
1207 ]
1208 },
1209 {
1210 code: "([obj.fo_o] = bar);",
1211 parserOptions: { ecmaVersion: 6 },
1212 errors: [
1213 {
1214 messageId: "notCamelCase",
1215 data: { name: "fo_o" },
1216 type: "Identifier"
1217 }
1218 ]
1219 },
1220 {
1221 code: "([obj.fo_o] = bar);",
1222 options: [{ ignoreDestructuring: true }],
1223 parserOptions: { ecmaVersion: 6 },
1224 errors: [
1225 {
1226 messageId: "notCamelCase",
1227 data: { name: "fo_o" },
1228 type: "Identifier"
1229 }
1230 ]
1231 },
1232 {
1233 code: "([obj.fo_o = 1] = bar);",
1234 options: [{ properties: "always" }],
1235 parserOptions: { ecmaVersion: 6 },
1236 errors: [
1237 {
1238 messageId: "notCamelCase",
1239 data: { name: "fo_o" },
1240 type: "Identifier"
1241 }
1242 ]
1243 },
1244 {
1245 code: "({ a: [obj.fo_o] } = bar);",
1246 parserOptions: { ecmaVersion: 6 },
1247 errors: [
1248 {
1249 messageId: "notCamelCase",
1250 data: { name: "fo_o" },
1251 type: "Identifier"
1252 }
1253 ]
1254 },
1255 {
1256 code: "({ a: { b: [obj.fo_o] } } = bar);",
1257 parserOptions: { ecmaVersion: 6 },
1258 errors: [
1259 {
1260 messageId: "notCamelCase",
1261 data: { name: "fo_o" },
1262 type: "Identifier"
1263 }
1264 ]
1265 },
1266 {
1267 code: "([obj.fo_o.ba_r] = baz);",
1268 parserOptions: { ecmaVersion: 6 },
1269 errors: [
1270 {
1271 messageId: "notCamelCase",
1272 data: { name: "ba_r" },
1273 type: "Identifier"
1274 }
1275 ]
1276 },
1277 {
1278 code: "({...obj.fo_o} = baz);",
1279 parserOptions: { ecmaVersion: 9 },
1280 errors: [
1281 {
1282 messageId: "notCamelCase",
1283 data: { name: "fo_o" },
1284 type: "Identifier"
1285 }
1286 ]
1287 },
1288 {
1289 code: "({...obj.fo_o.ba_r} = baz);",
1290 parserOptions: { ecmaVersion: 9 },
1291 errors: [
1292 {
1293 messageId: "notCamelCase",
1294 data: { name: "ba_r" },
1295 type: "Identifier"
1296 }
1297 ]
1298 },
1299 {
1300 code: "({c: {...obj.fo_o }} = baz);",
1301 parserOptions: { ecmaVersion: 9 },
1302 errors: [
1303 {
1304 messageId: "notCamelCase",
1305 data: { name: "fo_o" },
1306 type: "Identifier"
1307 }
1308 ]
1309 },
1310
1311 // Optional chaining.
1312 {
1313 code: "obj.o_k.non_camelcase = 0",
1314 options: [{ properties: "always" }],
1315 parserOptions: { ecmaVersion: 2020 },
1316 errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }]
1317 },
1318 {
1319 code: "(obj?.o_k).non_camelcase = 0",
1320 options: [{ properties: "always" }],
1321 parserOptions: { ecmaVersion: 2020 },
1322 errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }]
1323 }
1324 ]
1325 });