]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/camelcase.js
514eb85d2ef6901ad1ae166d3023c4a0f03bb812
2 * @fileoverview Tests for camelcase rule.
3 * @author Nicholas C. Zakas
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/camelcase"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("camelcase", rule
, {
23 "firstName = \"Nicholas\"",
24 "FIRST_NAME = \"Nicholas\"",
25 "__myPrivateVariable = \"Patrick\"",
26 "myPrivateVariable_ = \"Patrick\"",
27 "function doSomething(){}",
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];",
39 "var arr = [foo.bar_baz.qux];",
40 "[foo.bar_baz.nesting]",
41 "if (foo.bar_baz === boom.bam_pow) { [foo.baz_boom] }",
43 code
: "var o = {key: 1}",
44 options
: [{ properties
: "always" }]
47 code
: "var o = {_leading: 1}",
48 options
: [{ properties
: "always" }]
51 code
: "var o = {trailing_: 1}",
52 options
: [{ properties
: "always" }]
55 code
: "var o = {bar_baz: 1}",
56 options
: [{ properties
: "never" }]
59 code
: "var o = {_leading: 1}",
60 options
: [{ properties
: "never" }]
63 code
: "var o = {trailing_: 1}",
64 options
: [{ properties
: "never" }]
68 options
: [{ properties
: "never" }]
72 options
: [{ properties
: "always" }]
76 options
: [{ properties
: "always" }]
80 options
: [{ properties
: "never" }]
84 options
: [{ properties
: "never" }]
87 code
: "var obj = {\n a_a: 1 \n};\n obj.a_b = 2;",
88 options
: [{ properties
: "never" }]
91 code
: "obj.foo_bar = function(){};",
92 options
: [{ properties
: "never" }]
95 code
: "const { ['foo']: _foo } = obj;",
96 parserOptions
: { ecmaVersion
: 6 }
99 code
: "const { [_foo_]: foo } = obj;",
100 parserOptions
: { ecmaVersion
: 6 }
103 code
: "var { category_id } = query;",
104 options
: [{ ignoreDestructuring
: true }],
105 parserOptions
: { ecmaVersion
: 6 }
108 code
: "var { category_id: category_id } = query;",
109 options
: [{ ignoreDestructuring
: true }],
110 parserOptions
: { ecmaVersion
: 6 }
113 code
: "var { category_id = 1 } = query;",
114 options
: [{ ignoreDestructuring
: true }],
115 parserOptions
: { ecmaVersion
: 6 }
118 code
: "var { [{category_id} = query]: categoryId } = query;",
119 options
: [{ ignoreDestructuring
: true }],
120 parserOptions
: { ecmaVersion
: 6 }
123 code
: "var { category_id: category } = query;",
124 parserOptions
: { ecmaVersion
: 6 }
127 code
: "var { _leading } = query;",
128 parserOptions
: { ecmaVersion
: 6 }
131 code
: "var { trailing_ } = query;",
132 parserOptions
: { ecmaVersion
: 6 }
135 code
: "import { camelCased } from \"external module\";",
136 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" }
139 code
: "import { _leading } from \"external module\";",
140 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" }
143 code
: "import { trailing_ } from \"external module\";",
144 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" }
147 code
: "import { no_camelcased as camelCased } from \"external-module\";",
148 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" }
151 code
: "import { no_camelcased as _leading } from \"external-module\";",
152 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" }
155 code
: "import { no_camelcased as trailing_ } from \"external-module\";",
156 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" }
159 code
: "import { no_camelcased as camelCased, anotherCamelCased } from \"external-module\";",
160 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" }
163 code
: "import { snake_cased } from 'mod'",
164 options
: [{ ignoreImports
: true }],
165 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" }
168 code
: "import { camelCased } from 'mod'",
169 options
: [{ ignoreImports
: false }],
170 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" }
173 code
: "var _camelCased = aGlobalVariable",
174 options
: [{ ignoreGlobals
: false }],
175 globals
: { aGlobalVariable
: "readonly" }
178 code
: "var camelCased = _aGlobalVariable",
179 options
: [{ ignoreGlobals
: false }],
180 globals
: { _aGlobalVariable
: "readonly" }
183 code
: "var camelCased = a_global_variable",
184 options
: [{ ignoreGlobals
: true }],
185 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
188 code
: "a_global_variable.foo()",
189 options
: [{ ignoreGlobals
: true }],
190 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
193 code
: "a_global_variable[undefined]",
194 options
: [{ ignoreGlobals
: true }],
195 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
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
203 code
: "a_global_variable.foo = bar",
204 options
: [{ ignoreGlobals
: true }],
205 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
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
214 code
: "a_global_variable = foo",
215 options
: [{ ignoreGlobals
: true }],
216 globals
: { a_global_variable
: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase
219 code
: "a_global_variable = foo",
220 options
: [{ ignoreGlobals
: true }],
221 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
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
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
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
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
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
254 code
: "foo[a_global_variable] = bar",
255 options
: [{ ignoreGlobals
: true }],
256 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
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
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
271 code
: "function foo({ no_camelcased: camelCased }) {};",
272 parserOptions
: { ecmaVersion
: 6 }
275 code
: "function foo({ no_camelcased: _leading }) {};",
276 parserOptions
: { ecmaVersion
: 6 }
279 code
: "function foo({ no_camelcased: trailing_ }) {};",
280 parserOptions
: { ecmaVersion
: 6 }
283 code
: "function foo({ camelCased = 'default value' }) {};",
284 parserOptions
: { ecmaVersion
: 6 }
287 code
: "function foo({ _leading = 'default value' }) {};",
288 parserOptions
: { ecmaVersion
: 6 }
291 code
: "function foo({ trailing_ = 'default value' }) {};",
292 parserOptions
: { ecmaVersion
: 6 }
295 code
: "function foo({ camelCased }) {};",
296 parserOptions
: { ecmaVersion
: 6 }
299 code
: "function foo({ _leading }) {}",
300 parserOptions
: { ecmaVersion
: 6 }
303 code
: "function foo({ trailing_ }) {}",
304 parserOptions
: { ecmaVersion
: 6 }
307 code
: "ignored_foo = 0;",
308 options
: [{ allow
: ["ignored_foo"] }]
311 code
: "ignored_foo = 0; ignored_bar = 1;",
312 options
: [{ allow
: ["ignored_foo", "ignored_bar"] }]
315 code
: "user_id = 0;",
316 options
: [{ allow
: ["_id$"] }]
319 code
: "__option_foo__ = 0;",
320 options
: [{ allow
: ["__option_foo__"] }]
323 code
: "foo = { [computedBar]: 0 };",
324 options
: [{ ignoreDestructuring
: true }],
325 parserOptions
: { ecmaVersion
: 6 }
328 code
: "({ a: obj.fo_o } = bar);",
329 options
: [{ allow
: ["fo_o"] }],
330 parserOptions
: { ecmaVersion
: 6 }
333 code
: "({ a: obj.foo } = bar);",
334 options
: [{ allow
: ["fo_o"] }],
335 parserOptions
: { ecmaVersion
: 6 }
338 code
: "({ a: obj.fo_o } = bar);",
339 options
: [{ properties
: "never" }],
340 parserOptions
: { ecmaVersion
: 6 }
343 code
: "({ a: obj.fo_o.b_ar } = bar);",
344 options
: [{ properties
: "never" }],
345 parserOptions
: { ecmaVersion
: 6 }
348 code
: "({ a: { b: obj.fo_o } } = bar);",
349 options
: [{ properties
: "never" }],
350 parserOptions
: { ecmaVersion
: 6 }
353 code
: "([obj.fo_o] = bar);",
354 options
: [{ properties
: "never" }],
355 parserOptions
: { ecmaVersion
: 6 }
358 code
: "({ c: [ob.fo_o]} = bar);",
359 options
: [{ properties
: "never" }],
360 parserOptions
: { ecmaVersion
: 6 }
363 code
: "([obj.fo_o.b_ar] = bar);",
364 options
: [{ properties
: "never" }],
365 parserOptions
: { ecmaVersion
: 6 }
368 code
: "({obj} = baz.fo_o);",
369 parserOptions
: { ecmaVersion
: 6 }
372 code
: "([obj] = baz.fo_o);",
373 parserOptions
: { ecmaVersion
: 6 }
376 code
: "([obj.foo = obj.fo_o] = bar);",
377 options
: [{ properties
: "always" }],
378 parserOptions
: { ecmaVersion
: 6 }
381 code
: "class C { camelCase; #camelCase; #camelCase2() {} }",
382 options
: [{ properties
: "always" }],
383 parserOptions
: { ecmaVersion
: 2022 }
386 code
: "class C { snake_case; #snake_case; #snake_case2() {} }",
387 options
: [{ properties
: "never" }],
388 parserOptions
: { ecmaVersion
: 2022 }
393 code
: "first_name = \"Nicholas\"",
396 messageId
: "notCamelCase",
397 data
: { name
: "first_name" },
403 code
: "__private_first_name = \"Patrick\"",
406 messageId
: "notCamelCase",
407 data
: { name
: "__private_first_name" },
413 code
: "function foo_bar(){}",
416 messageId
: "notCamelCase",
417 data
: { name
: "foo_bar" },
423 code
: "obj.foo_bar = function(){};",
426 messageId
: "notCamelCase",
427 data
: { name
: "foo_bar" },
433 code
: "bar_baz.foo = function(){};",
436 messageId
: "notCamelCase",
437 data
: { name
: "bar_baz" },
443 code
: "[foo_bar.baz]",
446 messageId
: "notCamelCase",
447 data
: { name
: "foo_bar" },
453 code
: "if (foo.bar_baz === boom.bam_pow) { [foo_bar.baz] }",
456 messageId
: "notCamelCase",
457 data
: { name
: "foo_bar" },
463 code
: "foo.bar_baz = boom.bam_pow",
466 messageId
: "notCamelCase",
467 data
: { name
: "bar_baz" },
473 code
: "var foo = { bar_baz: boom.bam_pow }",
476 messageId
: "notCamelCase",
477 data
: { name
: "bar_baz" },
483 code
: "var foo = { bar_baz: boom.bam_pow }",
484 options
: [{ ignoreDestructuring
: true }],
487 messageId
: "notCamelCase",
488 data
: { name
: "bar_baz" },
494 code
: "foo.qux.boom_pow = { bar: boom.bam_pow }",
497 messageId
: "notCamelCase",
498 data
: { name
: "boom_pow" },
504 code
: "var o = {bar_baz: 1}",
505 options
: [{ properties
: "always" }],
508 messageId
: "notCamelCase",
509 data
: { name
: "bar_baz" },
515 code
: "obj.a_b = 2;",
516 options
: [{ properties
: "always" }],
519 messageId
: "notCamelCase",
520 data
: { name
: "a_b" },
526 code
: "var { category_id: category_alias } = query;",
527 parserOptions
: { ecmaVersion
: 6 },
530 messageId
: "notCamelCase",
531 data
: { name
: "category_alias" },
537 code
: "var { category_id: category_alias } = query;",
538 options
: [{ ignoreDestructuring
: true }],
539 parserOptions
: { ecmaVersion
: 6 },
542 messageId
: "notCamelCase",
543 data
: { name
: "category_alias" },
549 code
: "var { [category_id]: categoryId } = query;",
550 options
: [{ ignoreDestructuring
: true }],
551 parserOptions
: { ecmaVersion
: 6 },
554 messageId
: "notCamelCase",
555 data
: { name
: "category_id" },
561 code
: "var { [category_id]: categoryId } = query;",
562 parserOptions
: { ecmaVersion
: 6 },
565 messageId
: "notCamelCase",
566 data
: { name
: "category_id" },
572 code
: "var { category_id: categoryId, ...other_props } = query;",
573 options
: [{ ignoreDestructuring
: true }],
574 parserOptions
: { ecmaVersion
: 2018 },
577 messageId
: "notCamelCase",
578 data
: { name
: "other_props" },
584 code
: "var { category_id } = query;",
585 parserOptions
: { ecmaVersion
: 6 },
588 messageId
: "notCamelCase",
589 data
: { name
: "category_id" },
595 code
: "var { category_id: category_id } = query;",
596 parserOptions
: { ecmaVersion
: 6 },
599 messageId
: "notCamelCase",
600 data
: { name
: "category_id" },
606 code
: "var { category_id = 1 } = query;",
607 parserOptions
: { ecmaVersion
: 6 },
610 messageId
: "notCamelCase",
611 data
: { name
: "category_id" },
617 code
: "import no_camelcased from \"external-module\";",
618 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
621 messageId
: "notCamelCase",
622 data
: { name
: "no_camelcased" },
628 code
: "import * as no_camelcased from \"external-module\";",
629 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
632 messageId
: "notCamelCase",
633 data
: { name
: "no_camelcased" },
639 code
: "import { no_camelcased } from \"external-module\";",
640 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
643 messageId
: "notCamelCase",
644 data
: { name
: "no_camelcased" },
650 code
: "import { no_camelcased as no_camel_cased } from \"external module\";",
651 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
654 messageId
: "notCamelCase",
655 data
: { name
: "no_camel_cased" },
661 code
: "import { camelCased as no_camel_cased } from \"external module\";",
662 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
665 messageId
: "notCamelCase",
666 data
: { name
: "no_camel_cased" },
672 code
: "import { camelCased, no_camelcased } from \"external-module\";",
673 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
676 messageId
: "notCamelCase",
677 data
: { name
: "no_camelcased" },
683 code
: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";",
684 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
687 messageId
: "notCamelCase",
688 data
: { name
: "another_no_camelcased" },
694 code
: "import camelCased, { no_camelcased } from \"external-module\";",
695 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
698 messageId
: "notCamelCase",
699 data
: { name
: "no_camelcased" },
705 code
: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";",
706 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
709 messageId
: "notCamelCase",
710 data
: { name
: "no_camelcased" },
716 code
: "import snake_cased from 'mod'",
717 options
: [{ ignoreImports
: true }],
718 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
721 messageId
: "notCamelCase",
722 data
: { name
: "snake_cased" },
728 code
: "import * as snake_cased from 'mod'",
729 options
: [{ ignoreImports
: true }],
730 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
733 messageId
: "notCamelCase",
734 data
: { name
: "snake_cased" },
740 code
: "import snake_cased from 'mod'",
741 options
: [{ ignoreImports
: false }],
742 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
745 messageId
: "notCamelCase",
746 data
: { name
: "snake_cased" },
752 code
: "import * as snake_cased from 'mod'",
753 options
: [{ ignoreImports
: false }],
754 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
757 messageId
: "notCamelCase",
758 data
: { name
: "snake_cased" },
764 code
: "var camelCased = snake_cased",
765 options
: [{ ignoreGlobals
: false }],
766 globals
: { snake_cased
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
769 messageId
: "notCamelCase",
770 data
: { name
: "snake_cased" },
776 code
: "a_global_variable.foo()",
777 options
: [{ ignoreGlobals
: false }],
778 globals
: { snake_cased
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
781 messageId
: "notCamelCase",
782 data
: { name
: "a_global_variable" },
788 code
: "a_global_variable[undefined]",
789 options
: [{ ignoreGlobals
: false }],
790 globals
: { snake_cased
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
793 messageId
: "notCamelCase",
794 data
: { name
: "a_global_variable" },
800 code
: "var camelCased = snake_cased",
801 globals
: { snake_cased
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
804 messageId
: "notCamelCase",
805 data
: { name
: "snake_cased" },
811 code
: "var camelCased = snake_cased",
813 globals
: { snake_cased
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
816 messageId
: "notCamelCase",
817 data
: { name
: "snake_cased" },
823 code
: "foo.a_global_variable = bar",
824 options
: [{ ignoreGlobals
: true }],
825 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
828 messageId
: "notCamelCase",
829 data
: { name
: "a_global_variable" },
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
840 messageId
: "notCamelCase",
841 data
: { name
: "a_global_variable" },
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
852 messageId
: "notCamelCase",
853 data
: { name
: "a_global_variable" },
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
866 messageId
: "notCamelCase",
867 data
: { name
: "a_global_variable" },
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
879 messageId
: "notCamelCase",
880 data
: { name
: "a_global_variable" },
886 code
: "a_global_variable: for (;;);",
887 options
: [{ ignoreGlobals
: true }],
888 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
891 messageId
: "notCamelCase",
892 data
: { name
: "a_global_variable" },
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
904 messageId
: "notCamelCase",
905 data
: { name
: "a_global_variable" },
910 messageId
: "notCamelCase",
911 data
: { name
: "a_global_variable" },
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
924 messageId
: "notCamelCase",
925 data
: { name
: "a_global_variable" },
930 messageId
: "notCamelCase",
931 data
: { name
: "a_global_variable" },
938 code
: "var a_global_variable",
939 options
: [{ ignoreGlobals
: true }],
940 parserOptions
: { ecmaVersion
: 6 },
943 messageId
: "notCamelCase",
944 data
: { name
: "a_global_variable" },
950 code
: "function a_global_variable () {}",
951 options
: [{ ignoreGlobals
: true }],
952 parserOptions
: { ecmaVersion
: 6 },
955 messageId
: "notCamelCase",
956 data
: { name
: "a_global_variable" },
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
968 messageId
: "notCamelCase",
969 data
: { name
: "a_global_variable" },
974 messageId
: "notCamelCase",
975 data
: { name
: "a_global_variable" },
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
988 messageId
: "notCamelCase",
989 data
: { name
: "a_global_variable" },
994 messageId
: "notCamelCase",
995 data
: { name
: "a_global_variable" },
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
1008 messageId
: "notCamelCase",
1009 data
: { name
: "a_global_variable" },
1015 code
: "undefined_variable;",
1016 options
: [{ ignoreGlobals
: true }],
1019 messageId
: "notCamelCase",
1020 data
: { name
: "undefined_variable" },
1026 code
: "implicit_global = 1;",
1027 options
: [{ ignoreGlobals
: true }],
1030 messageId
: "notCamelCase",
1031 data
: { name
: "implicit_global" },
1037 code
: "export * as snake_cased from 'mod'",
1038 parserOptions
: { ecmaVersion
: 2020, sourceType
: "module" },
1041 messageId
: "notCamelCase",
1042 data
: { name
: "snake_cased" },
1048 code
: "function foo({ no_camelcased }) {};",
1049 parserOptions
: { ecmaVersion
: 6 },
1052 messageId
: "notCamelCase",
1053 data
: { name
: "no_camelcased" },
1059 code
: "function foo({ no_camelcased = 'default value' }) {};",
1060 parserOptions
: { ecmaVersion
: 6 },
1063 messageId
: "notCamelCase",
1064 data
: { name
: "no_camelcased" },
1070 code
: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}",
1071 parserOptions
: { ecmaVersion
: 6 },
1074 messageId
: "notCamelCase",
1075 data
: { name
: "no_camelcased" },
1079 messageId
: "notCamelCase",
1080 data
: { name
: "camelcased_value" },
1086 code
: "const { bar: no_camelcased } = foo;",
1087 parserOptions
: { ecmaVersion
: 6 },
1090 messageId
: "notCamelCase",
1091 data
: { name
: "no_camelcased" },
1097 code
: "function foo({ value_1: my_default }) {}",
1098 parserOptions
: { ecmaVersion
: 6 },
1101 messageId
: "notCamelCase",
1102 data
: { name
: "my_default" },
1108 code
: "function foo({ isCamelcased: no_camelcased }) {};",
1109 parserOptions
: { ecmaVersion
: 6 },
1112 messageId
: "notCamelCase",
1113 data
: { name
: "no_camelcased" },
1119 code
: "var { foo: bar_baz = 1 } = quz;",
1120 parserOptions
: { ecmaVersion
: 6 },
1123 messageId
: "notCamelCase",
1124 data
: { name
: "bar_baz" },
1130 code
: "const { no_camelcased = false } = bar;",
1131 parserOptions
: { ecmaVersion
: 6 },
1134 messageId
: "notCamelCase",
1135 data
: { name
: "no_camelcased" },
1141 code
: "const { no_camelcased = foo_bar } = bar;",
1142 parserOptions
: { ecmaVersion
: 6 },
1145 messageId
: "notCamelCase",
1146 data
: { name
: "no_camelcased" },
1152 code
: "not_ignored_foo = 0;",
1153 options
: [{ allow
: ["ignored_bar"] }],
1156 messageId
: "notCamelCase",
1157 data
: { name
: "not_ignored_foo" },
1163 code
: "not_ignored_foo = 0;",
1164 options
: [{ allow
: ["_id$"] }],
1167 messageId
: "notCamelCase",
1168 data
: { name
: "not_ignored_foo" },
1174 code
: "foo = { [computed_bar]: 0 };",
1175 options
: [{ ignoreDestructuring
: true }],
1176 parserOptions
: { ecmaVersion
: 6 },
1179 messageId
: "notCamelCase",
1180 data
: { name
: "computed_bar" },
1186 code
: "({ a: obj.fo_o } = bar);",
1187 parserOptions
: { ecmaVersion
: 6 },
1190 messageId
: "notCamelCase",
1191 data
: { name
: "fo_o" },
1197 code
: "({ a: obj.fo_o } = bar);",
1198 options
: [{ ignoreDestructuring
: true }],
1199 parserOptions
: { ecmaVersion
: 6 },
1202 messageId
: "notCamelCase",
1203 data
: { name
: "fo_o" },
1209 code
: "({ a: obj.fo_o.b_ar } = baz);",
1210 parserOptions
: { ecmaVersion
: 6 },
1213 messageId
: "notCamelCase",
1214 data
: { name
: "b_ar" },
1220 code
: "({ a: { b: { c: obj.fo_o } } } = bar);",
1221 parserOptions
: { ecmaVersion
: 6 },
1224 messageId
: "notCamelCase",
1225 data
: { name
: "fo_o" },
1231 code
: "({ a: { b: { c: obj.fo_o.b_ar } } } = baz);",
1232 parserOptions
: { ecmaVersion
: 6 },
1235 messageId
: "notCamelCase",
1236 data
: { name
: "b_ar" },
1242 code
: "([obj.fo_o] = bar);",
1243 parserOptions
: { ecmaVersion
: 6 },
1246 messageId
: "notCamelCase",
1247 data
: { name
: "fo_o" },
1253 code
: "([obj.fo_o] = bar);",
1254 options
: [{ ignoreDestructuring
: true }],
1255 parserOptions
: { ecmaVersion
: 6 },
1258 messageId
: "notCamelCase",
1259 data
: { name
: "fo_o" },
1265 code
: "([obj.fo_o = 1] = bar);",
1266 options
: [{ properties
: "always" }],
1267 parserOptions
: { ecmaVersion
: 6 },
1270 messageId
: "notCamelCase",
1271 data
: { name
: "fo_o" },
1277 code
: "({ a: [obj.fo_o] } = bar);",
1278 parserOptions
: { ecmaVersion
: 6 },
1281 messageId
: "notCamelCase",
1282 data
: { name
: "fo_o" },
1288 code
: "({ a: { b: [obj.fo_o] } } = bar);",
1289 parserOptions
: { ecmaVersion
: 6 },
1292 messageId
: "notCamelCase",
1293 data
: { name
: "fo_o" },
1299 code
: "([obj.fo_o.ba_r] = baz);",
1300 parserOptions
: { ecmaVersion
: 6 },
1303 messageId
: "notCamelCase",
1304 data
: { name
: "ba_r" },
1310 code
: "({...obj.fo_o} = baz);",
1311 parserOptions
: { ecmaVersion
: 9 },
1314 messageId
: "notCamelCase",
1315 data
: { name
: "fo_o" },
1321 code
: "({...obj.fo_o.ba_r} = baz);",
1322 parserOptions
: { ecmaVersion
: 9 },
1325 messageId
: "notCamelCase",
1326 data
: { name
: "ba_r" },
1332 code
: "({c: {...obj.fo_o }} = baz);",
1333 parserOptions
: { ecmaVersion
: 9 },
1336 messageId
: "notCamelCase",
1337 data
: { name
: "fo_o" },
1343 // Optional chaining.
1345 code
: "obj.o_k.non_camelcase = 0",
1346 options
: [{ properties
: "always" }],
1347 parserOptions
: { ecmaVersion
: 2020 },
1348 errors
: [{ messageId
: "notCamelCase", data
: { name
: "non_camelcase" } }]
1351 code
: "(obj?.o_k).non_camelcase = 0",
1352 options
: [{ properties
: "always" }],
1353 parserOptions
: { ecmaVersion
: 2020 },
1354 errors
: [{ messageId
: "notCamelCase", data
: { name
: "non_camelcase" } }]
1357 // class public/private fields, private methods.
1359 code
: "class C { snake_case; }",
1360 options
: [{ properties
: "always" }],
1361 parserOptions
: { ecmaVersion
: 2022 },
1362 errors
: [{ messageId
: "notCamelCase", data
: { name
: "snake_case" } }]
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 }]
1371 code
: "class C { #snake_case() {} }",
1372 options
: [{ properties
: "always" }],
1373 parserOptions
: { ecmaVersion
: 2022 },
1374 errors
: [{ messageId
: "notCamelCasePrivate", data
: { name
: "snake_case" } }]