]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/camelcase.js
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 { snake_cased as snake_cased } from 'mod'",
169 options
: [{ ignoreImports
: true }],
170 parserOptions
: { ecmaVersion
: 2022, sourceType
: "module" }
173 code
: "import { 'snake_cased' as snake_cased } from 'mod'",
174 options
: [{ ignoreImports
: true }],
175 parserOptions
: { ecmaVersion
: 2022, sourceType
: "module" }
178 code
: "import { camelCased } from 'mod'",
179 options
: [{ ignoreImports
: false }],
180 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" }
183 // this rule doesn't apply to quoted module export names, as it doesn't apply to quoted property names.
185 code
: "export { a as 'snake_cased' } from 'mod'",
186 parserOptions
: { ecmaVersion
: 2022, sourceType
: "module" }
189 code
: "export * as 'snake_cased' from 'mod'",
190 parserOptions
: { ecmaVersion
: 2022, sourceType
: "module" }
194 code
: "var _camelCased = aGlobalVariable",
195 options
: [{ ignoreGlobals
: false }],
196 globals
: { aGlobalVariable
: "readonly" }
199 code
: "var camelCased = _aGlobalVariable",
200 options
: [{ ignoreGlobals
: false }],
201 globals
: { _aGlobalVariable
: "readonly" }
204 code
: "var camelCased = a_global_variable",
205 options
: [{ ignoreGlobals
: true }],
206 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
209 code
: "a_global_variable.foo()",
210 options
: [{ ignoreGlobals
: true }],
211 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
214 code
: "a_global_variable[undefined]",
215 options
: [{ ignoreGlobals
: true }],
216 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
219 code
: "var foo = a_global_variable.bar",
220 options
: [{ ignoreGlobals
: true }],
221 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
224 code
: "a_global_variable.foo = bar",
225 options
: [{ ignoreGlobals
: true }],
226 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
229 code
: "( { foo: a_global_variable.bar } = baz )",
230 options
: [{ ignoreGlobals
: true }],
231 parserOptions
: { ecmaVersion
: 6 },
232 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
235 code
: "a_global_variable = foo",
236 options
: [{ ignoreGlobals
: true }],
237 globals
: { a_global_variable
: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase
240 code
: "a_global_variable = foo",
241 options
: [{ ignoreGlobals
: true }],
242 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
245 code
: "({ a_global_variable } = foo)",
246 options
: [{ ignoreGlobals
: true }],
247 parserOptions
: { ecmaVersion
: 6 },
248 globals
: { a_global_variable
: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase
251 code
: "({ snake_cased: a_global_variable } = foo)",
252 options
: [{ ignoreGlobals
: true }],
253 parserOptions
: { ecmaVersion
: 6 },
254 globals
: { a_global_variable
: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase
257 code
: "({ snake_cased: a_global_variable = foo } = bar)",
258 options
: [{ ignoreGlobals
: true }],
259 parserOptions
: { ecmaVersion
: 6 },
260 globals
: { a_global_variable
: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase
263 code
: "[a_global_variable] = bar",
264 options
: [{ ignoreGlobals
: true }],
265 parserOptions
: { ecmaVersion
: 6 },
266 globals
: { a_global_variable
: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase
269 code
: "[a_global_variable = foo] = bar",
270 options
: [{ ignoreGlobals
: true }],
271 parserOptions
: { ecmaVersion
: 6 },
272 globals
: { a_global_variable
: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase
275 code
: "foo[a_global_variable] = bar",
276 options
: [{ ignoreGlobals
: true }],
277 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
280 code
: "var foo = { [a_global_variable]: bar }",
281 options
: [{ ignoreGlobals
: true }],
282 parserOptions
: { ecmaVersion
: 6 },
283 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
286 code
: "var { [a_global_variable]: foo } = bar",
287 options
: [{ ignoreGlobals
: true }],
288 parserOptions
: { ecmaVersion
: 6 },
289 globals
: { a_global_variable
: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase
292 code
: "function foo({ no_camelcased: camelCased }) {};",
293 parserOptions
: { ecmaVersion
: 6 }
296 code
: "function foo({ no_camelcased: _leading }) {};",
297 parserOptions
: { ecmaVersion
: 6 }
300 code
: "function foo({ no_camelcased: trailing_ }) {};",
301 parserOptions
: { ecmaVersion
: 6 }
304 code
: "function foo({ camelCased = 'default value' }) {};",
305 parserOptions
: { ecmaVersion
: 6 }
308 code
: "function foo({ _leading = 'default value' }) {};",
309 parserOptions
: { ecmaVersion
: 6 }
312 code
: "function foo({ trailing_ = 'default value' }) {};",
313 parserOptions
: { ecmaVersion
: 6 }
316 code
: "function foo({ camelCased }) {};",
317 parserOptions
: { ecmaVersion
: 6 }
320 code
: "function foo({ _leading }) {}",
321 parserOptions
: { ecmaVersion
: 6 }
324 code
: "function foo({ trailing_ }) {}",
325 parserOptions
: { ecmaVersion
: 6 }
328 code
: "ignored_foo = 0;",
329 options
: [{ allow
: ["ignored_foo"] }]
332 code
: "ignored_foo = 0; ignored_bar = 1;",
333 options
: [{ allow
: ["ignored_foo", "ignored_bar"] }]
336 code
: "user_id = 0;",
337 options
: [{ allow
: ["_id$"] }]
340 code
: "__option_foo__ = 0;",
341 options
: [{ allow
: ["__option_foo__"] }]
344 code
: "foo = { [computedBar]: 0 };",
345 options
: [{ ignoreDestructuring
: true }],
346 parserOptions
: { ecmaVersion
: 6 }
349 code
: "({ a: obj.fo_o } = bar);",
350 options
: [{ allow
: ["fo_o"] }],
351 parserOptions
: { ecmaVersion
: 6 }
354 code
: "({ a: obj.foo } = bar);",
355 options
: [{ allow
: ["fo_o"] }],
356 parserOptions
: { ecmaVersion
: 6 }
359 code
: "({ a: obj.fo_o } = bar);",
360 options
: [{ properties
: "never" }],
361 parserOptions
: { ecmaVersion
: 6 }
364 code
: "({ a: obj.fo_o.b_ar } = bar);",
365 options
: [{ properties
: "never" }],
366 parserOptions
: { ecmaVersion
: 6 }
369 code
: "({ a: { b: obj.fo_o } } = bar);",
370 options
: [{ properties
: "never" }],
371 parserOptions
: { ecmaVersion
: 6 }
374 code
: "([obj.fo_o] = bar);",
375 options
: [{ properties
: "never" }],
376 parserOptions
: { ecmaVersion
: 6 }
379 code
: "({ c: [ob.fo_o]} = bar);",
380 options
: [{ properties
: "never" }],
381 parserOptions
: { ecmaVersion
: 6 }
384 code
: "([obj.fo_o.b_ar] = bar);",
385 options
: [{ properties
: "never" }],
386 parserOptions
: { ecmaVersion
: 6 }
389 code
: "({obj} = baz.fo_o);",
390 parserOptions
: { ecmaVersion
: 6 }
393 code
: "([obj] = baz.fo_o);",
394 parserOptions
: { ecmaVersion
: 6 }
397 code
: "([obj.foo = obj.fo_o] = bar);",
398 options
: [{ properties
: "always" }],
399 parserOptions
: { ecmaVersion
: 6 }
402 code
: "class C { camelCase; #camelCase; #camelCase2() {} }",
403 options
: [{ properties
: "always" }],
404 parserOptions
: { ecmaVersion
: 2022 }
407 code
: "class C { snake_case; #snake_case; #snake_case2() {} }",
408 options
: [{ properties
: "never" }],
409 parserOptions
: { ecmaVersion
: 2022 }
412 // Combinations of `properties` and `ignoreDestructuring`
415 const { some_property } = obj;
417 const bar = { some_property };
419 obj.some_property = 10;
421 const xyz = { some_property: obj.some_property };
423 const foo = ({ some_property }) => {
424 console.log(some_property)
427 options
: [{ properties
: "never", ignoreDestructuring
: true }],
428 parserOptions
: { ecmaVersion
: 2022 }
431 // https://github.com/eslint/eslint/issues/15572
434 const { some_property } = obj;
435 doSomething({ some_property });
437 options
: [{ properties
: "never", ignoreDestructuring
: true }],
438 parserOptions
: { ecmaVersion
: 2022 }
443 code
: "first_name = \"Nicholas\"",
446 messageId
: "notCamelCase",
447 data
: { name
: "first_name" },
453 code
: "__private_first_name = \"Patrick\"",
456 messageId
: "notCamelCase",
457 data
: { name
: "__private_first_name" },
463 code
: "function foo_bar(){}",
466 messageId
: "notCamelCase",
467 data
: { name
: "foo_bar" },
473 code
: "obj.foo_bar = function(){};",
476 messageId
: "notCamelCase",
477 data
: { name
: "foo_bar" },
483 code
: "bar_baz.foo = function(){};",
486 messageId
: "notCamelCase",
487 data
: { name
: "bar_baz" },
493 code
: "[foo_bar.baz]",
496 messageId
: "notCamelCase",
497 data
: { name
: "foo_bar" },
503 code
: "if (foo.bar_baz === boom.bam_pow) { [foo_bar.baz] }",
506 messageId
: "notCamelCase",
507 data
: { name
: "foo_bar" },
513 code
: "foo.bar_baz = boom.bam_pow",
516 messageId
: "notCamelCase",
517 data
: { name
: "bar_baz" },
523 code
: "var foo = { bar_baz: boom.bam_pow }",
526 messageId
: "notCamelCase",
527 data
: { name
: "bar_baz" },
533 code
: "var foo = { bar_baz: boom.bam_pow }",
534 options
: [{ ignoreDestructuring
: true }],
537 messageId
: "notCamelCase",
538 data
: { name
: "bar_baz" },
544 code
: "foo.qux.boom_pow = { bar: boom.bam_pow }",
547 messageId
: "notCamelCase",
548 data
: { name
: "boom_pow" },
554 code
: "var o = {bar_baz: 1}",
555 options
: [{ properties
: "always" }],
558 messageId
: "notCamelCase",
559 data
: { name
: "bar_baz" },
565 code
: "obj.a_b = 2;",
566 options
: [{ properties
: "always" }],
569 messageId
: "notCamelCase",
570 data
: { name
: "a_b" },
576 code
: "var { category_id: category_alias } = query;",
577 parserOptions
: { ecmaVersion
: 6 },
580 messageId
: "notCamelCase",
581 data
: { name
: "category_alias" },
587 code
: "var { category_id: category_alias } = query;",
588 options
: [{ ignoreDestructuring
: true }],
589 parserOptions
: { ecmaVersion
: 6 },
592 messageId
: "notCamelCase",
593 data
: { name
: "category_alias" },
599 code
: "var { [category_id]: categoryId } = query;",
600 options
: [{ ignoreDestructuring
: true }],
601 parserOptions
: { ecmaVersion
: 6 },
604 messageId
: "notCamelCase",
605 data
: { name
: "category_id" },
611 code
: "var { [category_id]: categoryId } = query;",
612 parserOptions
: { ecmaVersion
: 6 },
615 messageId
: "notCamelCase",
616 data
: { name
: "category_id" },
622 code
: "var { category_id: categoryId, ...other_props } = query;",
623 options
: [{ ignoreDestructuring
: true }],
624 parserOptions
: { ecmaVersion
: 2018 },
627 messageId
: "notCamelCase",
628 data
: { name
: "other_props" },
634 code
: "var { category_id } = query;",
635 parserOptions
: { ecmaVersion
: 6 },
638 messageId
: "notCamelCase",
639 data
: { name
: "category_id" },
645 code
: "var { category_id: category_id } = query;",
646 parserOptions
: { ecmaVersion
: 6 },
649 messageId
: "notCamelCase",
650 data
: { name
: "category_id" },
656 code
: "var { category_id = 1 } = query;",
657 parserOptions
: { ecmaVersion
: 6 },
660 messageId
: "notCamelCase",
661 data
: { name
: "category_id" },
667 code
: "import no_camelcased from \"external-module\";",
668 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
671 messageId
: "notCamelCase",
672 data
: { name
: "no_camelcased" },
678 code
: "import * as no_camelcased from \"external-module\";",
679 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
682 messageId
: "notCamelCase",
683 data
: { name
: "no_camelcased" },
689 code
: "import { no_camelcased } from \"external-module\";",
690 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
693 messageId
: "notCamelCase",
694 data
: { name
: "no_camelcased" },
700 code
: "import { no_camelcased as no_camel_cased } from \"external module\";",
701 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
704 messageId
: "notCamelCase",
705 data
: { name
: "no_camel_cased" },
711 code
: "import { camelCased as no_camel_cased } from \"external module\";",
712 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
715 messageId
: "notCamelCase",
716 data
: { name
: "no_camel_cased" },
722 code
: "import { 'snake_cased' as snake_cased } from 'mod'",
723 parserOptions
: { ecmaVersion
: 2022, sourceType
: "module" },
726 messageId
: "notCamelCase",
727 data
: { name
: "snake_cased" },
733 code
: "import { 'snake_cased' as another_snake_cased } from 'mod'",
734 options
: [{ ignoreImports
: true }],
735 parserOptions
: { ecmaVersion
: 2022, sourceType
: "module" },
738 messageId
: "notCamelCase",
739 data
: { name
: "another_snake_cased" },
745 code
: "import { camelCased, no_camelcased } from \"external-module\";",
746 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
749 messageId
: "notCamelCase",
750 data
: { name
: "no_camelcased" },
756 code
: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";",
757 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
760 messageId
: "notCamelCase",
761 data
: { name
: "another_no_camelcased" },
767 code
: "import camelCased, { no_camelcased } from \"external-module\";",
768 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
771 messageId
: "notCamelCase",
772 data
: { name
: "no_camelcased" },
778 code
: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";",
779 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
782 messageId
: "notCamelCase",
783 data
: { name
: "no_camelcased" },
789 code
: "import snake_cased from 'mod'",
790 options
: [{ ignoreImports
: true }],
791 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
794 messageId
: "notCamelCase",
795 data
: { name
: "snake_cased" },
801 code
: "import * as snake_cased from 'mod'",
802 options
: [{ ignoreImports
: true }],
803 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
806 messageId
: "notCamelCase",
807 data
: { name
: "snake_cased" },
813 code
: "import snake_cased from 'mod'",
814 options
: [{ ignoreImports
: false }],
815 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
818 messageId
: "notCamelCase",
819 data
: { name
: "snake_cased" },
825 code
: "import * as snake_cased from 'mod'",
826 options
: [{ ignoreImports
: false }],
827 parserOptions
: { ecmaVersion
: 6, sourceType
: "module" },
830 messageId
: "notCamelCase",
831 data
: { name
: "snake_cased" },
837 code
: "var camelCased = snake_cased",
838 options
: [{ ignoreGlobals
: false }],
839 globals
: { snake_cased
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
842 messageId
: "notCamelCase",
843 data
: { name
: "snake_cased" },
849 code
: "a_global_variable.foo()",
850 options
: [{ ignoreGlobals
: false }],
851 globals
: { snake_cased
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
854 messageId
: "notCamelCase",
855 data
: { name
: "a_global_variable" },
861 code
: "a_global_variable[undefined]",
862 options
: [{ ignoreGlobals
: false }],
863 globals
: { snake_cased
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
866 messageId
: "notCamelCase",
867 data
: { name
: "a_global_variable" },
873 code
: "var camelCased = snake_cased",
874 globals
: { snake_cased
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
877 messageId
: "notCamelCase",
878 data
: { name
: "snake_cased" },
884 code
: "var camelCased = snake_cased",
886 globals
: { snake_cased
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
889 messageId
: "notCamelCase",
890 data
: { name
: "snake_cased" },
896 code
: "foo.a_global_variable = bar",
897 options
: [{ ignoreGlobals
: true }],
898 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
901 messageId
: "notCamelCase",
902 data
: { name
: "a_global_variable" },
908 code
: "var foo = { a_global_variable: bar }",
909 options
: [{ ignoreGlobals
: true }],
910 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
913 messageId
: "notCamelCase",
914 data
: { name
: "a_global_variable" },
920 code
: "var foo = { a_global_variable: a_global_variable }",
921 options
: [{ ignoreGlobals
: true }],
922 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
925 messageId
: "notCamelCase",
926 data
: { name
: "a_global_variable" },
933 code
: "var foo = { a_global_variable() {} }",
934 options
: [{ ignoreGlobals
: true }],
935 parserOptions
: { ecmaVersion
: 6 },
936 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
939 messageId
: "notCamelCase",
940 data
: { name
: "a_global_variable" },
946 code
: "class Foo { a_global_variable() {} }",
947 options
: [{ ignoreGlobals
: true }],
948 parserOptions
: { ecmaVersion
: 6 },
949 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
952 messageId
: "notCamelCase",
953 data
: { name
: "a_global_variable" },
959 code
: "a_global_variable: for (;;);",
960 options
: [{ ignoreGlobals
: true }],
961 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
964 messageId
: "notCamelCase",
965 data
: { name
: "a_global_variable" },
971 code
: "if (foo) { let a_global_variable; a_global_variable = bar; }",
972 options
: [{ ignoreGlobals
: true }],
973 parserOptions
: { ecmaVersion
: 6 },
974 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
977 messageId
: "notCamelCase",
978 data
: { name
: "a_global_variable" },
983 messageId
: "notCamelCase",
984 data
: { name
: "a_global_variable" },
991 code
: "function foo(a_global_variable) { foo = a_global_variable; }",
992 options
: [{ ignoreGlobals
: true }],
993 parserOptions
: { ecmaVersion
: 6 },
994 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
997 messageId
: "notCamelCase",
998 data
: { name
: "a_global_variable" },
1003 messageId
: "notCamelCase",
1004 data
: { name
: "a_global_variable" },
1011 code
: "var a_global_variable",
1012 options
: [{ ignoreGlobals
: true }],
1013 parserOptions
: { ecmaVersion
: 6 },
1016 messageId
: "notCamelCase",
1017 data
: { name
: "a_global_variable" },
1023 code
: "function a_global_variable () {}",
1024 options
: [{ ignoreGlobals
: true }],
1025 parserOptions
: { ecmaVersion
: 6 },
1028 messageId
: "notCamelCase",
1029 data
: { name
: "a_global_variable" },
1035 code
: "const a_global_variable = foo; bar = a_global_variable",
1036 options
: [{ ignoreGlobals
: true }],
1037 parserOptions
: { ecmaVersion
: 6 },
1038 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
1041 messageId
: "notCamelCase",
1042 data
: { name
: "a_global_variable" },
1047 messageId
: "notCamelCase",
1048 data
: { name
: "a_global_variable" },
1055 code
: "bar = a_global_variable; var a_global_variable;",
1056 options
: [{ ignoreGlobals
: true }],
1057 parserOptions
: { ecmaVersion
: 6 },
1058 globals
: { a_global_variable
: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase
1061 messageId
: "notCamelCase",
1062 data
: { name
: "a_global_variable" },
1067 messageId
: "notCamelCase",
1068 data
: { name
: "a_global_variable" },
1075 code
: "var foo = { a_global_variable }",
1076 options
: [{ ignoreGlobals
: true }],
1077 parserOptions
: { ecmaVersion
: 6 },
1078 globals
: { a_global_variable
: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase
1081 messageId
: "notCamelCase",
1082 data
: { name
: "a_global_variable" },
1088 code
: "undefined_variable;",
1089 options
: [{ ignoreGlobals
: true }],
1092 messageId
: "notCamelCase",
1093 data
: { name
: "undefined_variable" },
1099 code
: "implicit_global = 1;",
1100 options
: [{ ignoreGlobals
: true }],
1103 messageId
: "notCamelCase",
1104 data
: { name
: "implicit_global" },
1110 code
: "export * as snake_cased from 'mod'",
1111 parserOptions
: { ecmaVersion
: 2020, sourceType
: "module" },
1114 messageId
: "notCamelCase",
1115 data
: { name
: "snake_cased" },
1121 code
: "function foo({ no_camelcased }) {};",
1122 parserOptions
: { ecmaVersion
: 6 },
1125 messageId
: "notCamelCase",
1126 data
: { name
: "no_camelcased" },
1132 code
: "function foo({ no_camelcased = 'default value' }) {};",
1133 parserOptions
: { ecmaVersion
: 6 },
1136 messageId
: "notCamelCase",
1137 data
: { name
: "no_camelcased" },
1143 code
: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}",
1144 parserOptions
: { ecmaVersion
: 6 },
1147 messageId
: "notCamelCase",
1148 data
: { name
: "no_camelcased" },
1152 messageId
: "notCamelCase",
1153 data
: { name
: "camelcased_value" },
1159 code
: "const { bar: no_camelcased } = foo;",
1160 parserOptions
: { ecmaVersion
: 6 },
1163 messageId
: "notCamelCase",
1164 data
: { name
: "no_camelcased" },
1170 code
: "function foo({ value_1: my_default }) {}",
1171 parserOptions
: { ecmaVersion
: 6 },
1174 messageId
: "notCamelCase",
1175 data
: { name
: "my_default" },
1181 code
: "function foo({ isCamelcased: no_camelcased }) {};",
1182 parserOptions
: { ecmaVersion
: 6 },
1185 messageId
: "notCamelCase",
1186 data
: { name
: "no_camelcased" },
1192 code
: "var { foo: bar_baz = 1 } = quz;",
1193 parserOptions
: { ecmaVersion
: 6 },
1196 messageId
: "notCamelCase",
1197 data
: { name
: "bar_baz" },
1203 code
: "const { no_camelcased = false } = bar;",
1204 parserOptions
: { ecmaVersion
: 6 },
1207 messageId
: "notCamelCase",
1208 data
: { name
: "no_camelcased" },
1214 code
: "const { no_camelcased = foo_bar } = bar;",
1215 parserOptions
: { ecmaVersion
: 6 },
1218 messageId
: "notCamelCase",
1219 data
: { name
: "no_camelcased" },
1225 code
: "not_ignored_foo = 0;",
1226 options
: [{ allow
: ["ignored_bar"] }],
1229 messageId
: "notCamelCase",
1230 data
: { name
: "not_ignored_foo" },
1236 code
: "not_ignored_foo = 0;",
1237 options
: [{ allow
: ["_id$"] }],
1240 messageId
: "notCamelCase",
1241 data
: { name
: "not_ignored_foo" },
1247 code
: "foo = { [computed_bar]: 0 };",
1248 options
: [{ ignoreDestructuring
: true }],
1249 parserOptions
: { ecmaVersion
: 6 },
1252 messageId
: "notCamelCase",
1253 data
: { name
: "computed_bar" },
1259 code
: "({ a: obj.fo_o } = bar);",
1260 parserOptions
: { ecmaVersion
: 6 },
1263 messageId
: "notCamelCase",
1264 data
: { name
: "fo_o" },
1270 code
: "({ a: obj.fo_o } = bar);",
1271 options
: [{ ignoreDestructuring
: true }],
1272 parserOptions
: { ecmaVersion
: 6 },
1275 messageId
: "notCamelCase",
1276 data
: { name
: "fo_o" },
1282 code
: "({ a: obj.fo_o.b_ar } = baz);",
1283 parserOptions
: { ecmaVersion
: 6 },
1286 messageId
: "notCamelCase",
1287 data
: { name
: "b_ar" },
1293 code
: "({ a: { b: { c: obj.fo_o } } } = bar);",
1294 parserOptions
: { ecmaVersion
: 6 },
1297 messageId
: "notCamelCase",
1298 data
: { name
: "fo_o" },
1304 code
: "({ a: { b: { c: obj.fo_o.b_ar } } } = baz);",
1305 parserOptions
: { ecmaVersion
: 6 },
1308 messageId
: "notCamelCase",
1309 data
: { name
: "b_ar" },
1315 code
: "([obj.fo_o] = bar);",
1316 parserOptions
: { ecmaVersion
: 6 },
1319 messageId
: "notCamelCase",
1320 data
: { name
: "fo_o" },
1326 code
: "([obj.fo_o] = bar);",
1327 options
: [{ ignoreDestructuring
: true }],
1328 parserOptions
: { ecmaVersion
: 6 },
1331 messageId
: "notCamelCase",
1332 data
: { name
: "fo_o" },
1338 code
: "([obj.fo_o = 1] = bar);",
1339 options
: [{ properties
: "always" }],
1340 parserOptions
: { ecmaVersion
: 6 },
1343 messageId
: "notCamelCase",
1344 data
: { name
: "fo_o" },
1350 code
: "({ a: [obj.fo_o] } = bar);",
1351 parserOptions
: { ecmaVersion
: 6 },
1354 messageId
: "notCamelCase",
1355 data
: { name
: "fo_o" },
1361 code
: "({ a: { b: [obj.fo_o] } } = bar);",
1362 parserOptions
: { ecmaVersion
: 6 },
1365 messageId
: "notCamelCase",
1366 data
: { name
: "fo_o" },
1372 code
: "([obj.fo_o.ba_r] = baz);",
1373 parserOptions
: { ecmaVersion
: 6 },
1376 messageId
: "notCamelCase",
1377 data
: { name
: "ba_r" },
1383 code
: "({...obj.fo_o} = baz);",
1384 parserOptions
: { ecmaVersion
: 9 },
1387 messageId
: "notCamelCase",
1388 data
: { name
: "fo_o" },
1394 code
: "({...obj.fo_o.ba_r} = baz);",
1395 parserOptions
: { ecmaVersion
: 9 },
1398 messageId
: "notCamelCase",
1399 data
: { name
: "ba_r" },
1405 code
: "({c: {...obj.fo_o }} = baz);",
1406 parserOptions
: { ecmaVersion
: 9 },
1409 messageId
: "notCamelCase",
1410 data
: { name
: "fo_o" },
1416 // Optional chaining.
1418 code
: "obj.o_k.non_camelcase = 0",
1419 options
: [{ properties
: "always" }],
1420 parserOptions
: { ecmaVersion
: 2020 },
1421 errors
: [{ messageId
: "notCamelCase", data
: { name
: "non_camelcase" } }]
1424 code
: "(obj?.o_k).non_camelcase = 0",
1425 options
: [{ properties
: "always" }],
1426 parserOptions
: { ecmaVersion
: 2020 },
1427 errors
: [{ messageId
: "notCamelCase", data
: { name
: "non_camelcase" } }]
1430 // class public/private fields, private methods.
1432 code
: "class C { snake_case; }",
1433 options
: [{ properties
: "always" }],
1434 parserOptions
: { ecmaVersion
: 2022 },
1435 errors
: [{ messageId
: "notCamelCase", data
: { name
: "snake_case" } }]
1438 code
: "class C { #snake_case; foo() { this.#snake_case; } }",
1439 options
: [{ properties
: "always" }],
1440 parserOptions
: { ecmaVersion
: 2022 },
1441 errors
: [{ messageId
: "notCamelCasePrivate", data
: { name
: "snake_case" }, column
: 11 }]
1444 code
: "class C { #snake_case() {} }",
1445 options
: [{ properties
: "always" }],
1446 parserOptions
: { ecmaVersion
: 2022 },
1447 errors
: [{ messageId
: "notCamelCasePrivate", data
: { name
: "snake_case" } }]
1450 // Combinations of `properties` and `ignoreDestructuring`
1453 const { some_property } = obj;
1454 doSomething({ some_property });
1456 options
: [{ properties
: "always", ignoreDestructuring
: true }],
1457 parserOptions
: { ecmaVersion
: 2022 },
1460 messageId
: "notCamelCase",
1461 data
: { name
: "some_property" },
1469 const { some_property } = obj;
1470 doSomething({ some_property });
1471 doSomething({ [some_property]: "bar" });
1473 options
: [{ properties
: "never", ignoreDestructuring
: true }],
1474 parserOptions
: { ecmaVersion
: 2022 },
1477 messageId
: "notCamelCase",
1478 data
: { name
: "some_property" },
1486 const { some_property } = obj;
1488 const bar = { some_property };
1490 obj.some_property = 10;
1492 const xyz = { some_property: obj.some_property };
1494 const foo = ({ some_property }) => {
1495 console.log(some_property)
1498 options
: [{ properties
: "always", ignoreDestructuring
: true }],
1499 parserOptions
: { ecmaVersion
: 2022 },
1502 messageId
: "notCamelCase",
1503 data
: { name
: "some_property" },
1508 messageId
: "notCamelCase",
1509 data
: { name
: "some_property" },
1514 messageId
: "notCamelCase",
1515 data
: { name
: "some_property" },