]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/camelcase.js
514eb85d2ef6901ad1ae166d3023c4a0f03bb812
[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 -- Testing non-CamelCase
186 },
187 {
188 code: "a_global_variable.foo()",
189 options: [{ ignoreGlobals: true }],
190 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
191 },
192 {
193 code: "a_global_variable[undefined]",
194 options: [{ ignoreGlobals: true }],
195 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-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 -- Testing non-CamelCase
201 },
202 {
203 code: "a_global_variable.foo = bar",
204 options: [{ ignoreGlobals: true }],
205 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-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 -- Testing non-CamelCase
212 },
213 {
214 code: "a_global_variable = foo",
215 options: [{ ignoreGlobals: true }],
216 globals: { a_global_variable: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase
217 },
218 {
219 code: "a_global_variable = foo",
220 options: [{ ignoreGlobals: true }],
221 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-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 -- Testing non-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 -- Testing non-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 -- Testing non-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 -- Testing non-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 -- Testing non-CamelCase
252 },
253 {
254 code: "foo[a_global_variable] = bar",
255 options: [{ ignoreGlobals: true }],
256 globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-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 -- Testing non-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 -- Testing non-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 code: "class C { camelCase; #camelCase; #camelCase2() {} }",
382 options: [{ properties: "always" }],
383 parserOptions: { ecmaVersion: 2022 }
384 },
385 {
386 code: "class C { snake_case; #snake_case; #snake_case2() {} }",
387 options: [{ properties: "never" }],
388 parserOptions: { ecmaVersion: 2022 }
389 }
390 ],
391 invalid: [
392 {
393 code: "first_name = \"Nicholas\"",
394 errors: [
395 {
396 messageId: "notCamelCase",
397 data: { name: "first_name" },
398 type: "Identifier"
399 }
400 ]
401 },
402 {
403 code: "__private_first_name = \"Patrick\"",
404 errors: [
405 {
406 messageId: "notCamelCase",
407 data: { name: "__private_first_name" },
408 type: "Identifier"
409 }
410 ]
411 },
412 {
413 code: "function foo_bar(){}",
414 errors: [
415 {
416 messageId: "notCamelCase",
417 data: { name: "foo_bar" },
418 type: "Identifier"
419 }
420 ]
421 },
422 {
423 code: "obj.foo_bar = function(){};",
424 errors: [
425 {
426 messageId: "notCamelCase",
427 data: { name: "foo_bar" },
428 type: "Identifier"
429 }
430 ]
431 },
432 {
433 code: "bar_baz.foo = function(){};",
434 errors: [
435 {
436 messageId: "notCamelCase",
437 data: { name: "bar_baz" },
438 type: "Identifier"
439 }
440 ]
441 },
442 {
443 code: "[foo_bar.baz]",
444 errors: [
445 {
446 messageId: "notCamelCase",
447 data: { name: "foo_bar" },
448 type: "Identifier"
449 }
450 ]
451 },
452 {
453 code: "if (foo.bar_baz === boom.bam_pow) { [foo_bar.baz] }",
454 errors: [
455 {
456 messageId: "notCamelCase",
457 data: { name: "foo_bar" },
458 type: "Identifier"
459 }
460 ]
461 },
462 {
463 code: "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 errors: [
475 {
476 messageId: "notCamelCase",
477 data: { name: "bar_baz" },
478 type: "Identifier"
479 }
480 ]
481 },
482 {
483 code: "var foo = { bar_baz: boom.bam_pow }",
484 options: [{ ignoreDestructuring: true }],
485 errors: [
486 {
487 messageId: "notCamelCase",
488 data: { name: "bar_baz" },
489 type: "Identifier"
490 }
491 ]
492 },
493 {
494 code: "foo.qux.boom_pow = { bar: boom.bam_pow }",
495 errors: [
496 {
497 messageId: "notCamelCase",
498 data: { name: "boom_pow" },
499 type: "Identifier"
500 }
501 ]
502 },
503 {
504 code: "var o = {bar_baz: 1}",
505 options: [{ properties: "always" }],
506 errors: [
507 {
508 messageId: "notCamelCase",
509 data: { name: "bar_baz" },
510 type: "Identifier"
511 }
512 ]
513 },
514 {
515 code: "obj.a_b = 2;",
516 options: [{ properties: "always" }],
517 errors: [
518 {
519 messageId: "notCamelCase",
520 data: { name: "a_b" },
521 type: "Identifier"
522 }
523 ]
524 },
525 {
526 code: "var { category_id: category_alias } = query;",
527 parserOptions: { ecmaVersion: 6 },
528 errors: [
529 {
530 messageId: "notCamelCase",
531 data: { name: "category_alias" },
532 type: "Identifier"
533 }
534 ]
535 },
536 {
537 code: "var { category_id: category_alias } = query;",
538 options: [{ ignoreDestructuring: true }],
539 parserOptions: { ecmaVersion: 6 },
540 errors: [
541 {
542 messageId: "notCamelCase",
543 data: { name: "category_alias" },
544 type: "Identifier"
545 }
546 ]
547 },
548 {
549 code: "var { [category_id]: categoryId } = query;",
550 options: [{ ignoreDestructuring: true }],
551 parserOptions: { ecmaVersion: 6 },
552 errors: [
553 {
554 messageId: "notCamelCase",
555 data: { name: "category_id" },
556 type: "Identifier"
557 }
558 ]
559 },
560 {
561 code: "var { [category_id]: categoryId } = query;",
562 parserOptions: { ecmaVersion: 6 },
563 errors: [
564 {
565 messageId: "notCamelCase",
566 data: { name: "category_id" },
567 type: "Identifier"
568 }
569 ]
570 },
571 {
572 code: "var { category_id: categoryId, ...other_props } = query;",
573 options: [{ ignoreDestructuring: true }],
574 parserOptions: { ecmaVersion: 2018 },
575 errors: [
576 {
577 messageId: "notCamelCase",
578 data: { name: "other_props" },
579 type: "Identifier"
580 }
581 ]
582 },
583 {
584 code: "var { category_id } = query;",
585 parserOptions: { ecmaVersion: 6 },
586 errors: [
587 {
588 messageId: "notCamelCase",
589 data: { name: "category_id" },
590 type: "Identifier"
591 }
592 ]
593 },
594 {
595 code: "var { category_id: category_id } = query;",
596 parserOptions: { ecmaVersion: 6 },
597 errors: [
598 {
599 messageId: "notCamelCase",
600 data: { name: "category_id" },
601 type: "Identifier"
602 }
603 ]
604 },
605 {
606 code: "var { category_id = 1 } = query;",
607 parserOptions: { ecmaVersion: 6 },
608 errors: [
609 {
610 messageId: "notCamelCase",
611 data: { name: "category_id" },
612 type: "Identifier"
613 }
614 ]
615 },
616 {
617 code: "import no_camelcased from \"external-module\";",
618 parserOptions: { ecmaVersion: 6, sourceType: "module" },
619 errors: [
620 {
621 messageId: "notCamelCase",
622 data: { name: "no_camelcased" },
623 type: "Identifier"
624 }
625 ]
626 },
627 {
628 code: "import * as no_camelcased from \"external-module\";",
629 parserOptions: { ecmaVersion: 6, sourceType: "module" },
630 errors: [
631 {
632 messageId: "notCamelCase",
633 data: { name: "no_camelcased" },
634 type: "Identifier"
635 }
636 ]
637 },
638 {
639 code: "import { no_camelcased } from \"external-module\";",
640 parserOptions: { ecmaVersion: 6, sourceType: "module" },
641 errors: [
642 {
643 messageId: "notCamelCase",
644 data: { name: "no_camelcased" },
645 type: "Identifier"
646 }
647 ]
648 },
649 {
650 code: "import { no_camelcased as no_camel_cased } from \"external module\";",
651 parserOptions: { ecmaVersion: 6, sourceType: "module" },
652 errors: [
653 {
654 messageId: "notCamelCase",
655 data: { name: "no_camel_cased" },
656 type: "Identifier"
657 }
658 ]
659 },
660 {
661 code: "import { camelCased as no_camel_cased } from \"external module\";",
662 parserOptions: { ecmaVersion: 6, sourceType: "module" },
663 errors: [
664 {
665 messageId: "notCamelCase",
666 data: { name: "no_camel_cased" },
667 type: "Identifier"
668 }
669 ]
670 },
671 {
672 code: "import { camelCased, no_camelcased } from \"external-module\";",
673 parserOptions: { ecmaVersion: 6, sourceType: "module" },
674 errors: [
675 {
676 messageId: "notCamelCase",
677 data: { name: "no_camelcased" },
678 type: "Identifier"
679 }
680 ]
681 },
682 {
683 code: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";",
684 parserOptions: { ecmaVersion: 6, sourceType: "module" },
685 errors: [
686 {
687 messageId: "notCamelCase",
688 data: { name: "another_no_camelcased" },
689 type: "Identifier"
690 }
691 ]
692 },
693 {
694 code: "import camelCased, { no_camelcased } from \"external-module\";",
695 parserOptions: { ecmaVersion: 6, sourceType: "module" },
696 errors: [
697 {
698 messageId: "notCamelCase",
699 data: { name: "no_camelcased" },
700 type: "Identifier"
701 }
702 ]
703 },
704 {
705 code: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";",
706 parserOptions: { ecmaVersion: 6, sourceType: "module" },
707 errors: [
708 {
709 messageId: "notCamelCase",
710 data: { name: "no_camelcased" },
711 type: "Identifier"
712 }
713 ]
714 },
715 {
716 code: "import snake_cased from 'mod'",
717 options: [{ ignoreImports: true }],
718 parserOptions: { ecmaVersion: 6, sourceType: "module" },
719 errors: [
720 {
721 messageId: "notCamelCase",
722 data: { name: "snake_cased" },
723 type: "Identifier"
724 }
725 ]
726 },
727 {
728 code: "import * as snake_cased from 'mod'",
729 options: [{ ignoreImports: true }],
730 parserOptions: { ecmaVersion: 6, sourceType: "module" },
731 errors: [
732 {
733 messageId: "notCamelCase",
734 data: { name: "snake_cased" },
735 type: "Identifier"
736 }
737 ]
738 },
739 {
740 code: "import snake_cased from 'mod'",
741 options: [{ ignoreImports: false }],
742 parserOptions: { ecmaVersion: 6, sourceType: "module" },
743 errors: [
744 {
745 messageId: "notCamelCase",
746 data: { name: "snake_cased" },
747 type: "Identifier"
748 }
749 ]
750 },
751 {
752 code: "import * as snake_cased from 'mod'",
753 options: [{ ignoreImports: false }],
754 parserOptions: { ecmaVersion: 6, sourceType: "module" },
755 errors: [
756 {
757 messageId: "notCamelCase",
758 data: { name: "snake_cased" },
759 type: "Identifier"
760 }
761 ]
762 },
763 {
764 code: "var camelCased = snake_cased",
765 options: [{ ignoreGlobals: false }],
766 globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
767 errors: [
768 {
769 messageId: "notCamelCase",
770 data: { name: "snake_cased" },
771 type: "Identifier"
772 }
773 ]
774 },
775 {
776 code: "a_global_variable.foo()",
777 options: [{ ignoreGlobals: false }],
778 globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
779 errors: [
780 {
781 messageId: "notCamelCase",
782 data: { name: "a_global_variable" },
783 type: "Identifier"
784 }
785 ]
786 },
787 {
788 code: "a_global_variable[undefined]",
789 options: [{ ignoreGlobals: false }],
790 globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
791 errors: [
792 {
793 messageId: "notCamelCase",
794 data: { name: "a_global_variable" },
795 type: "Identifier"
796 }
797 ]
798 },
799 {
800 code: "var camelCased = snake_cased",
801 globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
802 errors: [
803 {
804 messageId: "notCamelCase",
805 data: { name: "snake_cased" },
806 type: "Identifier"
807 }
808 ]
809 },
810 {
811 code: "var camelCased = snake_cased",
812 options: [{}],
813 globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
814 errors: [
815 {
816 messageId: "notCamelCase",
817 data: { name: "snake_cased" },
818 type: "Identifier"
819 }
820 ]
821 },
822 {
823 code: "foo.a_global_variable = bar",
824 options: [{ ignoreGlobals: true }],
825 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
826 errors: [
827 {
828 messageId: "notCamelCase",
829 data: { name: "a_global_variable" },
830 type: "Identifier"
831 }
832 ]
833 },
834 {
835 code: "var foo = { a_global_variable: bar }",
836 options: [{ ignoreGlobals: true }],
837 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
838 errors: [
839 {
840 messageId: "notCamelCase",
841 data: { name: "a_global_variable" },
842 type: "Identifier"
843 }
844 ]
845 },
846 {
847 code: "var foo = { a_global_variable: a_global_variable }",
848 options: [{ ignoreGlobals: true }],
849 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
850 errors: [
851 {
852 messageId: "notCamelCase",
853 data: { name: "a_global_variable" },
854 type: "Identifier",
855 column: 13
856 }
857 ]
858 },
859 {
860 code: "var foo = { a_global_variable() {} }",
861 options: [{ ignoreGlobals: true }],
862 parserOptions: { ecmaVersion: 6 },
863 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
864 errors: [
865 {
866 messageId: "notCamelCase",
867 data: { name: "a_global_variable" },
868 type: "Identifier"
869 }
870 ]
871 },
872 {
873 code: "class Foo { a_global_variable() {} }",
874 options: [{ ignoreGlobals: true }],
875 parserOptions: { ecmaVersion: 6 },
876 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
877 errors: [
878 {
879 messageId: "notCamelCase",
880 data: { name: "a_global_variable" },
881 type: "Identifier"
882 }
883 ]
884 },
885 {
886 code: "a_global_variable: for (;;);",
887 options: [{ ignoreGlobals: true }],
888 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
889 errors: [
890 {
891 messageId: "notCamelCase",
892 data: { name: "a_global_variable" },
893 type: "Identifier"
894 }
895 ]
896 },
897 {
898 code: "if (foo) { let a_global_variable; a_global_variable = bar; }",
899 options: [{ ignoreGlobals: true }],
900 parserOptions: { ecmaVersion: 6 },
901 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
902 errors: [
903 {
904 messageId: "notCamelCase",
905 data: { name: "a_global_variable" },
906 type: "Identifier",
907 column: 16
908 },
909 {
910 messageId: "notCamelCase",
911 data: { name: "a_global_variable" },
912 type: "Identifier",
913 column: 35
914 }
915 ]
916 },
917 {
918 code: "function foo(a_global_variable) { foo = a_global_variable; }",
919 options: [{ ignoreGlobals: true }],
920 parserOptions: { ecmaVersion: 6 },
921 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
922 errors: [
923 {
924 messageId: "notCamelCase",
925 data: { name: "a_global_variable" },
926 type: "Identifier",
927 column: 14
928 },
929 {
930 messageId: "notCamelCase",
931 data: { name: "a_global_variable" },
932 type: "Identifier",
933 column: 41
934 }
935 ]
936 },
937 {
938 code: "var a_global_variable",
939 options: [{ ignoreGlobals: true }],
940 parserOptions: { ecmaVersion: 6 },
941 errors: [
942 {
943 messageId: "notCamelCase",
944 data: { name: "a_global_variable" },
945 type: "Identifier"
946 }
947 ]
948 },
949 {
950 code: "function a_global_variable () {}",
951 options: [{ ignoreGlobals: true }],
952 parserOptions: { ecmaVersion: 6 },
953 errors: [
954 {
955 messageId: "notCamelCase",
956 data: { name: "a_global_variable" },
957 type: "Identifier"
958 }
959 ]
960 },
961 {
962 code: "const a_global_variable = foo; bar = a_global_variable",
963 options: [{ ignoreGlobals: true }],
964 parserOptions: { ecmaVersion: 6 },
965 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
966 errors: [
967 {
968 messageId: "notCamelCase",
969 data: { name: "a_global_variable" },
970 type: "Identifier",
971 column: 7
972 },
973 {
974 messageId: "notCamelCase",
975 data: { name: "a_global_variable" },
976 type: "Identifier",
977 column: 38
978 }
979 ]
980 },
981 {
982 code: "bar = a_global_variable; var a_global_variable;",
983 options: [{ ignoreGlobals: true }],
984 parserOptions: { ecmaVersion: 6 },
985 globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
986 errors: [
987 {
988 messageId: "notCamelCase",
989 data: { name: "a_global_variable" },
990 type: "Identifier",
991 column: 7
992 },
993 {
994 messageId: "notCamelCase",
995 data: { name: "a_global_variable" },
996 type: "Identifier",
997 column: 30
998 }
999 ]
1000 },
1001 {
1002 code: "var foo = { a_global_variable }",
1003 options: [{ ignoreGlobals: true }],
1004 parserOptions: { ecmaVersion: 6 },
1005 globals: { a_global_variable: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
1006 errors: [
1007 {
1008 messageId: "notCamelCase",
1009 data: { name: "a_global_variable" },
1010 type: "Identifier"
1011 }
1012 ]
1013 },
1014 {
1015 code: "undefined_variable;",
1016 options: [{ ignoreGlobals: true }],
1017 errors: [
1018 {
1019 messageId: "notCamelCase",
1020 data: { name: "undefined_variable" },
1021 type: "Identifier"
1022 }
1023 ]
1024 },
1025 {
1026 code: "implicit_global = 1;",
1027 options: [{ ignoreGlobals: true }],
1028 errors: [
1029 {
1030 messageId: "notCamelCase",
1031 data: { name: "implicit_global" },
1032 type: "Identifier"
1033 }
1034 ]
1035 },
1036 {
1037 code: "export * as snake_cased from 'mod'",
1038 parserOptions: { ecmaVersion: 2020, sourceType: "module" },
1039 errors: [
1040 {
1041 messageId: "notCamelCase",
1042 data: { name: "snake_cased" },
1043 type: "Identifier"
1044 }
1045 ]
1046 },
1047 {
1048 code: "function foo({ no_camelcased }) {};",
1049 parserOptions: { ecmaVersion: 6 },
1050 errors: [
1051 {
1052 messageId: "notCamelCase",
1053 data: { name: "no_camelcased" },
1054 type: "Identifier"
1055 }
1056 ]
1057 },
1058 {
1059 code: "function foo({ no_camelcased = 'default value' }) {};",
1060 parserOptions: { ecmaVersion: 6 },
1061 errors: [
1062 {
1063 messageId: "notCamelCase",
1064 data: { name: "no_camelcased" },
1065 type: "Identifier"
1066 }
1067 ]
1068 },
1069 {
1070 code: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}",
1071 parserOptions: { ecmaVersion: 6 },
1072 errors: [
1073 {
1074 messageId: "notCamelCase",
1075 data: { name: "no_camelcased" },
1076 type: "Identifier"
1077 },
1078 {
1079 messageId: "notCamelCase",
1080 data: { name: "camelcased_value" },
1081 type: "Identifier"
1082 }
1083 ]
1084 },
1085 {
1086 code: "const { bar: no_camelcased } = foo;",
1087 parserOptions: { ecmaVersion: 6 },
1088 errors: [
1089 {
1090 messageId: "notCamelCase",
1091 data: { name: "no_camelcased" },
1092 type: "Identifier"
1093 }
1094 ]
1095 },
1096 {
1097 code: "function foo({ value_1: my_default }) {}",
1098 parserOptions: { ecmaVersion: 6 },
1099 errors: [
1100 {
1101 messageId: "notCamelCase",
1102 data: { name: "my_default" },
1103 type: "Identifier"
1104 }
1105 ]
1106 },
1107 {
1108 code: "function foo({ isCamelcased: no_camelcased }) {};",
1109 parserOptions: { ecmaVersion: 6 },
1110 errors: [
1111 {
1112 messageId: "notCamelCase",
1113 data: { name: "no_camelcased" },
1114 type: "Identifier"
1115 }
1116 ]
1117 },
1118 {
1119 code: "var { foo: bar_baz = 1 } = quz;",
1120 parserOptions: { ecmaVersion: 6 },
1121 errors: [
1122 {
1123 messageId: "notCamelCase",
1124 data: { name: "bar_baz" },
1125 type: "Identifier"
1126 }
1127 ]
1128 },
1129 {
1130 code: "const { no_camelcased = false } = bar;",
1131 parserOptions: { ecmaVersion: 6 },
1132 errors: [
1133 {
1134 messageId: "notCamelCase",
1135 data: { name: "no_camelcased" },
1136 type: "Identifier"
1137 }
1138 ]
1139 },
1140 {
1141 code: "const { no_camelcased = foo_bar } = bar;",
1142 parserOptions: { ecmaVersion: 6 },
1143 errors: [
1144 {
1145 messageId: "notCamelCase",
1146 data: { name: "no_camelcased" },
1147 type: "Identifier"
1148 }
1149 ]
1150 },
1151 {
1152 code: "not_ignored_foo = 0;",
1153 options: [{ allow: ["ignored_bar"] }],
1154 errors: [
1155 {
1156 messageId: "notCamelCase",
1157 data: { name: "not_ignored_foo" },
1158 type: "Identifier"
1159 }
1160 ]
1161 },
1162 {
1163 code: "not_ignored_foo = 0;",
1164 options: [{ allow: ["_id$"] }],
1165 errors: [
1166 {
1167 messageId: "notCamelCase",
1168 data: { name: "not_ignored_foo" },
1169 type: "Identifier"
1170 }
1171 ]
1172 },
1173 {
1174 code: "foo = { [computed_bar]: 0 };",
1175 options: [{ ignoreDestructuring: true }],
1176 parserOptions: { ecmaVersion: 6 },
1177 errors: [
1178 {
1179 messageId: "notCamelCase",
1180 data: { name: "computed_bar" },
1181 type: "Identifier"
1182 }
1183 ]
1184 },
1185 {
1186 code: "({ a: obj.fo_o } = bar);",
1187 parserOptions: { ecmaVersion: 6 },
1188 errors: [
1189 {
1190 messageId: "notCamelCase",
1191 data: { name: "fo_o" },
1192 type: "Identifier"
1193 }
1194 ]
1195 },
1196 {
1197 code: "({ a: obj.fo_o } = bar);",
1198 options: [{ ignoreDestructuring: true }],
1199 parserOptions: { ecmaVersion: 6 },
1200 errors: [
1201 {
1202 messageId: "notCamelCase",
1203 data: { name: "fo_o" },
1204 type: "Identifier"
1205 }
1206 ]
1207 },
1208 {
1209 code: "({ a: obj.fo_o.b_ar } = baz);",
1210 parserOptions: { ecmaVersion: 6 },
1211 errors: [
1212 {
1213 messageId: "notCamelCase",
1214 data: { name: "b_ar" },
1215 type: "Identifier"
1216 }
1217 ]
1218 },
1219 {
1220 code: "({ a: { b: { c: obj.fo_o } } } = bar);",
1221 parserOptions: { ecmaVersion: 6 },
1222 errors: [
1223 {
1224 messageId: "notCamelCase",
1225 data: { name: "fo_o" },
1226 type: "Identifier"
1227 }
1228 ]
1229 },
1230 {
1231 code: "({ a: { b: { c: obj.fo_o.b_ar } } } = baz);",
1232 parserOptions: { ecmaVersion: 6 },
1233 errors: [
1234 {
1235 messageId: "notCamelCase",
1236 data: { name: "b_ar" },
1237 type: "Identifier"
1238 }
1239 ]
1240 },
1241 {
1242 code: "([obj.fo_o] = bar);",
1243 parserOptions: { ecmaVersion: 6 },
1244 errors: [
1245 {
1246 messageId: "notCamelCase",
1247 data: { name: "fo_o" },
1248 type: "Identifier"
1249 }
1250 ]
1251 },
1252 {
1253 code: "([obj.fo_o] = bar);",
1254 options: [{ ignoreDestructuring: true }],
1255 parserOptions: { ecmaVersion: 6 },
1256 errors: [
1257 {
1258 messageId: "notCamelCase",
1259 data: { name: "fo_o" },
1260 type: "Identifier"
1261 }
1262 ]
1263 },
1264 {
1265 code: "([obj.fo_o = 1] = bar);",
1266 options: [{ properties: "always" }],
1267 parserOptions: { ecmaVersion: 6 },
1268 errors: [
1269 {
1270 messageId: "notCamelCase",
1271 data: { name: "fo_o" },
1272 type: "Identifier"
1273 }
1274 ]
1275 },
1276 {
1277 code: "({ a: [obj.fo_o] } = bar);",
1278 parserOptions: { ecmaVersion: 6 },
1279 errors: [
1280 {
1281 messageId: "notCamelCase",
1282 data: { name: "fo_o" },
1283 type: "Identifier"
1284 }
1285 ]
1286 },
1287 {
1288 code: "({ a: { b: [obj.fo_o] } } = bar);",
1289 parserOptions: { ecmaVersion: 6 },
1290 errors: [
1291 {
1292 messageId: "notCamelCase",
1293 data: { name: "fo_o" },
1294 type: "Identifier"
1295 }
1296 ]
1297 },
1298 {
1299 code: "([obj.fo_o.ba_r] = baz);",
1300 parserOptions: { ecmaVersion: 6 },
1301 errors: [
1302 {
1303 messageId: "notCamelCase",
1304 data: { name: "ba_r" },
1305 type: "Identifier"
1306 }
1307 ]
1308 },
1309 {
1310 code: "({...obj.fo_o} = baz);",
1311 parserOptions: { ecmaVersion: 9 },
1312 errors: [
1313 {
1314 messageId: "notCamelCase",
1315 data: { name: "fo_o" },
1316 type: "Identifier"
1317 }
1318 ]
1319 },
1320 {
1321 code: "({...obj.fo_o.ba_r} = baz);",
1322 parserOptions: { ecmaVersion: 9 },
1323 errors: [
1324 {
1325 messageId: "notCamelCase",
1326 data: { name: "ba_r" },
1327 type: "Identifier"
1328 }
1329 ]
1330 },
1331 {
1332 code: "({c: {...obj.fo_o }} = baz);",
1333 parserOptions: { ecmaVersion: 9 },
1334 errors: [
1335 {
1336 messageId: "notCamelCase",
1337 data: { name: "fo_o" },
1338 type: "Identifier"
1339 }
1340 ]
1341 },
1342
1343 // Optional chaining.
1344 {
1345 code: "obj.o_k.non_camelcase = 0",
1346 options: [{ properties: "always" }],
1347 parserOptions: { ecmaVersion: 2020 },
1348 errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }]
1349 },
1350 {
1351 code: "(obj?.o_k).non_camelcase = 0",
1352 options: [{ properties: "always" }],
1353 parserOptions: { ecmaVersion: 2020 },
1354 errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }]
1355 },
1356
1357 // class public/private fields, private methods.
1358 {
1359 code: "class C { snake_case; }",
1360 options: [{ properties: "always" }],
1361 parserOptions: { ecmaVersion: 2022 },
1362 errors: [{ messageId: "notCamelCase", data: { name: "snake_case" } }]
1363 },
1364 {
1365 code: "class C { #snake_case; foo() { this.#snake_case; } }",
1366 options: [{ properties: "always" }],
1367 parserOptions: { ecmaVersion: 2022 },
1368 errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" }, column: 11 }]
1369 },
1370 {
1371 code: "class C { #snake_case() {} }",
1372 options: [{ properties: "always" }],
1373 parserOptions: { ecmaVersion: 2022 },
1374 errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" } }]
1375 }
1376 ]
1377 });