]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
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: "function foo({ no_camelcased: camelCased }) {};", | |
174 | parserOptions: { ecmaVersion: 6 } | |
175 | }, | |
176 | { | |
177 | code: "function foo({ no_camelcased: _leading }) {};", | |
178 | parserOptions: { ecmaVersion: 6 } | |
179 | }, | |
180 | { | |
181 | code: "function foo({ no_camelcased: trailing_ }) {};", | |
182 | parserOptions: { ecmaVersion: 6 } | |
183 | }, | |
184 | { | |
185 | code: "function foo({ camelCased = 'default value' }) {};", | |
186 | parserOptions: { ecmaVersion: 6 } | |
187 | }, | |
188 | { | |
189 | code: "function foo({ _leading = 'default value' }) {};", | |
190 | parserOptions: { ecmaVersion: 6 } | |
191 | }, | |
192 | { | |
193 | code: "function foo({ trailing_ = 'default value' }) {};", | |
194 | parserOptions: { ecmaVersion: 6 } | |
195 | }, | |
196 | { | |
197 | code: "function foo({ camelCased }) {};", | |
198 | parserOptions: { ecmaVersion: 6 } | |
199 | }, | |
200 | { | |
201 | code: "function foo({ _leading }) {}", | |
202 | parserOptions: { ecmaVersion: 6 } | |
203 | }, | |
204 | { | |
205 | code: "function foo({ trailing_ }) {}", | |
206 | parserOptions: { ecmaVersion: 6 } | |
207 | }, | |
208 | { | |
209 | code: "ignored_foo = 0;", | |
210 | options: [{ allow: ["ignored_foo"] }] | |
211 | }, | |
212 | { | |
213 | code: "ignored_foo = 0; ignored_bar = 1;", | |
214 | options: [{ allow: ["ignored_foo", "ignored_bar"] }] | |
215 | }, | |
216 | { | |
217 | code: "user_id = 0;", | |
218 | options: [{ allow: ["_id$"] }] | |
219 | }, | |
220 | { | |
221 | code: "__option_foo__ = 0;", | |
222 | options: [{ allow: ["__option_foo__"] }] | |
223 | }, | |
224 | { | |
225 | code: "foo = { [computedBar]: 0 };", | |
226 | options: [{ ignoreDestructuring: true }], | |
227 | parserOptions: { ecmaVersion: 6 } | |
228 | }, | |
229 | { | |
230 | code: "({ a: obj.fo_o } = bar);", | |
231 | options: [{ allow: ["fo_o"] }], | |
232 | parserOptions: { ecmaVersion: 6 } | |
233 | }, | |
234 | { | |
235 | code: "({ a: obj.foo } = bar);", | |
236 | options: [{ allow: ["fo_o"] }], | |
237 | parserOptions: { ecmaVersion: 6 } | |
238 | }, | |
239 | { | |
240 | code: "({ a: obj.fo_o } = bar);", | |
241 | options: [{ properties: "never" }], | |
242 | parserOptions: { ecmaVersion: 6 } | |
243 | }, | |
244 | { | |
245 | code: "({ a: obj.fo_o.b_ar } = bar);", | |
246 | options: [{ properties: "never" }], | |
247 | parserOptions: { ecmaVersion: 6 } | |
248 | }, | |
249 | { | |
250 | code: "({ a: { b: obj.fo_o } } = bar);", | |
251 | options: [{ properties: "never" }], | |
252 | parserOptions: { ecmaVersion: 6 } | |
253 | }, | |
254 | { | |
255 | code: "([obj.fo_o] = bar);", | |
256 | options: [{ properties: "never" }], | |
257 | parserOptions: { ecmaVersion: 6 } | |
258 | }, | |
259 | { | |
260 | code: "({ c: [ob.fo_o]} = bar);", | |
261 | options: [{ properties: "never" }], | |
262 | parserOptions: { ecmaVersion: 6 } | |
263 | }, | |
264 | { | |
265 | code: "([obj.fo_o.b_ar] = bar);", | |
266 | options: [{ properties: "never" }], | |
267 | parserOptions: { ecmaVersion: 6 } | |
268 | }, | |
269 | { | |
270 | code: "({obj} = baz.fo_o);", | |
271 | parserOptions: { ecmaVersion: 6 } | |
272 | }, | |
273 | { | |
274 | code: "([obj] = baz.fo_o);", | |
275 | parserOptions: { ecmaVersion: 6 } | |
276 | }, | |
277 | { | |
278 | code: "([obj.foo = obj.fo_o] = bar);", | |
279 | options: [{ properties: "always" }], | |
280 | parserOptions: { ecmaVersion: 6 } | |
281 | } | |
282 | ], | |
283 | invalid: [ | |
284 | { | |
285 | code: "first_name = \"Nicholas\"", | |
286 | errors: [ | |
287 | { | |
288 | messageId: "notCamelCase", | |
289 | data: { name: "first_name" }, | |
290 | type: "Identifier" | |
291 | } | |
292 | ] | |
293 | }, | |
294 | { | |
295 | code: "__private_first_name = \"Patrick\"", | |
296 | errors: [ | |
297 | { | |
298 | messageId: "notCamelCase", | |
299 | data: { name: "__private_first_name" }, | |
300 | type: "Identifier" | |
301 | } | |
302 | ] | |
303 | }, | |
304 | { | |
305 | code: "function foo_bar(){}", | |
306 | errors: [ | |
307 | { | |
308 | messageId: "notCamelCase", | |
309 | data: { name: "foo_bar" }, | |
310 | type: "Identifier" | |
311 | } | |
312 | ] | |
313 | }, | |
314 | { | |
315 | code: "obj.foo_bar = function(){};", | |
316 | errors: [ | |
317 | { | |
318 | messageId: "notCamelCase", | |
319 | data: { name: "foo_bar" }, | |
320 | type: "Identifier" | |
321 | } | |
322 | ] | |
323 | }, | |
324 | { | |
325 | code: "bar_baz.foo = function(){};", | |
326 | errors: [ | |
327 | { | |
328 | messageId: "notCamelCase", | |
329 | data: { name: "bar_baz" }, | |
330 | type: "Identifier" | |
331 | } | |
332 | ] | |
333 | }, | |
334 | { | |
335 | code: "[foo_bar.baz]", | |
336 | errors: [ | |
337 | { | |
338 | messageId: "notCamelCase", | |
339 | data: { name: "foo_bar" }, | |
340 | type: "Identifier" | |
341 | } | |
342 | ] | |
343 | }, | |
344 | { | |
345 | code: "if (foo.bar_baz === boom.bam_pow) { [foo_bar.baz] }", | |
346 | errors: [ | |
347 | { | |
348 | messageId: "notCamelCase", | |
349 | data: { name: "foo_bar" }, | |
350 | type: "Identifier" | |
351 | } | |
352 | ] | |
353 | }, | |
354 | { | |
355 | code: "foo.bar_baz = boom.bam_pow", | |
356 | errors: [ | |
357 | { | |
358 | messageId: "notCamelCase", | |
359 | data: { name: "bar_baz" }, | |
360 | type: "Identifier" | |
361 | } | |
362 | ] | |
363 | }, | |
364 | { | |
365 | code: "var foo = { bar_baz: boom.bam_pow }", | |
366 | errors: [ | |
367 | { | |
368 | messageId: "notCamelCase", | |
369 | data: { name: "bar_baz" }, | |
370 | type: "Identifier" | |
371 | } | |
372 | ] | |
373 | }, | |
374 | { | |
375 | code: "var foo = { bar_baz: boom.bam_pow }", | |
376 | options: [{ ignoreDestructuring: true }], | |
377 | errors: [ | |
378 | { | |
379 | messageId: "notCamelCase", | |
380 | data: { name: "bar_baz" }, | |
381 | type: "Identifier" | |
382 | } | |
383 | ] | |
384 | }, | |
385 | { | |
386 | code: "foo.qux.boom_pow = { bar: boom.bam_pow }", | |
387 | errors: [ | |
388 | { | |
389 | messageId: "notCamelCase", | |
390 | data: { name: "boom_pow" }, | |
391 | type: "Identifier" | |
392 | } | |
393 | ] | |
394 | }, | |
395 | { | |
396 | code: "var o = {bar_baz: 1}", | |
397 | options: [{ properties: "always" }], | |
398 | errors: [ | |
399 | { | |
400 | messageId: "notCamelCase", | |
401 | data: { name: "bar_baz" }, | |
402 | type: "Identifier" | |
403 | } | |
404 | ] | |
405 | }, | |
406 | { | |
407 | code: "obj.a_b = 2;", | |
408 | options: [{ properties: "always" }], | |
409 | errors: [ | |
410 | { | |
411 | messageId: "notCamelCase", | |
412 | data: { name: "a_b" }, | |
413 | type: "Identifier" | |
414 | } | |
415 | ] | |
416 | }, | |
417 | { | |
418 | code: "var { category_id: category_alias } = query;", | |
419 | parserOptions: { ecmaVersion: 6 }, | |
420 | errors: [ | |
421 | { | |
422 | messageId: "notCamelCase", | |
423 | data: { name: "category_alias" }, | |
424 | type: "Identifier" | |
425 | } | |
426 | ] | |
427 | }, | |
428 | { | |
429 | code: "var { category_id: category_alias } = query;", | |
430 | options: [{ ignoreDestructuring: true }], | |
431 | parserOptions: { ecmaVersion: 6 }, | |
432 | errors: [ | |
433 | { | |
434 | messageId: "notCamelCase", | |
435 | data: { name: "category_alias" }, | |
436 | type: "Identifier" | |
437 | } | |
438 | ] | |
439 | }, | |
440 | { | |
441 | code: "var { [category_id]: categoryId } = query;", | |
442 | options: [{ ignoreDestructuring: true }], | |
443 | parserOptions: { ecmaVersion: 6 }, | |
444 | errors: [ | |
445 | { | |
446 | messageId: "notCamelCase", | |
447 | data: { name: "category_id" }, | |
448 | type: "Identifier" | |
449 | } | |
450 | ] | |
451 | }, | |
452 | { | |
453 | code: "var { [category_id]: categoryId } = query;", | |
454 | parserOptions: { ecmaVersion: 6 }, | |
455 | errors: [ | |
456 | { | |
457 | messageId: "notCamelCase", | |
458 | data: { name: "category_id" }, | |
459 | type: "Identifier" | |
460 | } | |
461 | ] | |
462 | }, | |
463 | { | |
464 | code: "var { category_id: categoryId, ...other_props } = query;", | |
465 | options: [{ ignoreDestructuring: true }], | |
466 | parserOptions: { ecmaVersion: 2018 }, | |
467 | errors: [ | |
468 | { | |
469 | messageId: "notCamelCase", | |
470 | data: { name: "other_props" }, | |
471 | type: "Identifier" | |
472 | } | |
473 | ] | |
474 | }, | |
475 | { | |
476 | code: "var { category_id } = query;", | |
477 | parserOptions: { ecmaVersion: 6 }, | |
478 | errors: [ | |
479 | { | |
480 | messageId: "notCamelCase", | |
481 | data: { name: "category_id" }, | |
482 | type: "Identifier" | |
483 | } | |
484 | ] | |
485 | }, | |
486 | { | |
487 | code: "var { category_id: category_id } = query;", | |
488 | parserOptions: { ecmaVersion: 6 }, | |
489 | errors: [ | |
490 | { | |
491 | messageId: "notCamelCase", | |
492 | data: { name: "category_id" }, | |
493 | type: "Identifier" | |
494 | } | |
495 | ] | |
496 | }, | |
497 | { | |
498 | code: "var { category_id = 1 } = query;", | |
499 | parserOptions: { ecmaVersion: 6 }, | |
500 | errors: [ | |
501 | { | |
502 | messageId: "notCamelCase", | |
503 | data: { name: "category_id" }, | |
504 | type: "Identifier" | |
505 | } | |
506 | ] | |
507 | }, | |
508 | { | |
509 | code: "import no_camelcased from \"external-module\";", | |
510 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
511 | errors: [ | |
512 | { | |
513 | messageId: "notCamelCase", | |
514 | data: { name: "no_camelcased" }, | |
515 | type: "Identifier" | |
516 | } | |
517 | ] | |
518 | }, | |
519 | { | |
520 | code: "import * as no_camelcased from \"external-module\";", | |
521 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
522 | errors: [ | |
523 | { | |
524 | messageId: "notCamelCase", | |
525 | data: { name: "no_camelcased" }, | |
526 | type: "Identifier" | |
527 | } | |
528 | ] | |
529 | }, | |
530 | { | |
531 | code: "import { no_camelcased } from \"external-module\";", | |
532 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
533 | errors: [ | |
534 | { | |
535 | messageId: "notCamelCase", | |
536 | data: { name: "no_camelcased" }, | |
537 | type: "Identifier" | |
538 | } | |
539 | ] | |
540 | }, | |
541 | { | |
542 | code: "import { no_camelcased as no_camel_cased } from \"external module\";", | |
543 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
544 | errors: [ | |
545 | { | |
546 | messageId: "notCamelCase", | |
547 | data: { name: "no_camel_cased" }, | |
548 | type: "Identifier" | |
549 | } | |
550 | ] | |
551 | }, | |
552 | { | |
553 | code: "import { camelCased as no_camel_cased } from \"external module\";", | |
554 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
555 | errors: [ | |
556 | { | |
557 | messageId: "notCamelCase", | |
558 | data: { name: "no_camel_cased" }, | |
559 | type: "Identifier" | |
560 | } | |
561 | ] | |
562 | }, | |
563 | { | |
564 | code: "import { camelCased, no_camelcased } from \"external-module\";", | |
565 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
566 | errors: [ | |
567 | { | |
568 | messageId: "notCamelCase", | |
569 | data: { name: "no_camelcased" }, | |
570 | type: "Identifier" | |
571 | } | |
572 | ] | |
573 | }, | |
574 | { | |
575 | code: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";", | |
576 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
577 | errors: [ | |
578 | { | |
579 | messageId: "notCamelCase", | |
580 | data: { name: "another_no_camelcased" }, | |
581 | type: "Identifier" | |
582 | } | |
583 | ] | |
584 | }, | |
585 | { | |
586 | code: "import camelCased, { no_camelcased } from \"external-module\";", | |
587 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
588 | errors: [ | |
589 | { | |
590 | messageId: "notCamelCase", | |
591 | data: { name: "no_camelcased" }, | |
592 | type: "Identifier" | |
593 | } | |
594 | ] | |
595 | }, | |
596 | { | |
597 | code: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";", | |
598 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
599 | errors: [ | |
600 | { | |
601 | messageId: "notCamelCase", | |
602 | data: { name: "no_camelcased" }, | |
603 | type: "Identifier" | |
604 | } | |
605 | ] | |
606 | }, | |
607 | { | |
608 | code: "import snake_cased from 'mod'", | |
609 | options: [{ ignoreImports: true }], | |
610 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
611 | errors: [ | |
612 | { | |
613 | messageId: "notCamelCase", | |
614 | data: { name: "snake_cased" }, | |
615 | type: "Identifier" | |
616 | } | |
617 | ] | |
618 | }, | |
619 | { | |
620 | code: "import * as snake_cased from 'mod'", | |
621 | options: [{ ignoreImports: true }], | |
622 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
623 | errors: [ | |
624 | { | |
625 | messageId: "notCamelCase", | |
626 | data: { name: "snake_cased" }, | |
627 | type: "Identifier" | |
628 | } | |
629 | ] | |
630 | }, | |
631 | { | |
632 | code: "import snake_cased from 'mod'", | |
633 | options: [{ ignoreImports: false }], | |
634 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
635 | errors: [ | |
636 | { | |
637 | messageId: "notCamelCase", | |
638 | data: { name: "snake_cased" }, | |
639 | type: "Identifier" | |
640 | } | |
641 | ] | |
642 | }, | |
643 | { | |
644 | code: "import * as snake_cased from 'mod'", | |
645 | options: [{ ignoreImports: false }], | |
646 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
647 | errors: [ | |
648 | { | |
649 | messageId: "notCamelCase", | |
650 | data: { name: "snake_cased" }, | |
651 | type: "Identifier" | |
652 | } | |
653 | ] | |
654 | }, | |
d3726936 TL |
655 | { |
656 | code: "export * as snake_cased from 'mod'", | |
657 | parserOptions: { ecmaVersion: 2020, sourceType: "module" }, | |
658 | errors: [ | |
659 | { | |
660 | messageId: "notCamelCase", | |
661 | data: { name: "snake_cased" }, | |
662 | type: "Identifier" | |
663 | } | |
664 | ] | |
665 | }, | |
eb39fafa DC |
666 | { |
667 | code: "function foo({ no_camelcased }) {};", | |
668 | parserOptions: { ecmaVersion: 6 }, | |
669 | errors: [ | |
670 | { | |
671 | messageId: "notCamelCase", | |
672 | data: { name: "no_camelcased" }, | |
673 | type: "Identifier" | |
674 | } | |
675 | ] | |
676 | }, | |
677 | { | |
678 | code: "function foo({ no_camelcased = 'default value' }) {};", | |
679 | parserOptions: { ecmaVersion: 6 }, | |
680 | errors: [ | |
681 | { | |
682 | messageId: "notCamelCase", | |
683 | data: { name: "no_camelcased" }, | |
684 | type: "Identifier" | |
685 | } | |
686 | ] | |
687 | }, | |
688 | { | |
689 | code: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}", | |
690 | parserOptions: { ecmaVersion: 6 }, | |
691 | errors: [ | |
692 | { | |
693 | messageId: "notCamelCase", | |
694 | data: { name: "no_camelcased" }, | |
695 | type: "Identifier" | |
696 | }, | |
697 | { | |
698 | messageId: "notCamelCase", | |
699 | data: { name: "camelcased_value" }, | |
700 | type: "Identifier" | |
701 | } | |
702 | ] | |
703 | }, | |
704 | { | |
705 | code: "const { bar: no_camelcased } = foo;", | |
706 | parserOptions: { ecmaVersion: 6 }, | |
707 | errors: [ | |
708 | { | |
709 | messageId: "notCamelCase", | |
710 | data: { name: "no_camelcased" }, | |
711 | type: "Identifier" | |
712 | } | |
713 | ] | |
714 | }, | |
715 | { | |
716 | code: "function foo({ value_1: my_default }) {}", | |
717 | parserOptions: { ecmaVersion: 6 }, | |
718 | errors: [ | |
719 | { | |
720 | messageId: "notCamelCase", | |
721 | data: { name: "my_default" }, | |
722 | type: "Identifier" | |
723 | } | |
724 | ] | |
725 | }, | |
726 | { | |
727 | code: "function foo({ isCamelcased: no_camelcased }) {};", | |
728 | parserOptions: { ecmaVersion: 6 }, | |
729 | errors: [ | |
730 | { | |
731 | messageId: "notCamelCase", | |
732 | data: { name: "no_camelcased" }, | |
733 | type: "Identifier" | |
734 | } | |
735 | ] | |
736 | }, | |
737 | { | |
738 | code: "var { foo: bar_baz = 1 } = quz;", | |
739 | parserOptions: { ecmaVersion: 6 }, | |
740 | errors: [ | |
741 | { | |
742 | messageId: "notCamelCase", | |
743 | data: { name: "bar_baz" }, | |
744 | type: "Identifier" | |
745 | } | |
746 | ] | |
747 | }, | |
748 | { | |
749 | code: "const { no_camelcased = false } = bar;", | |
750 | parserOptions: { ecmaVersion: 6 }, | |
751 | errors: [ | |
752 | { | |
753 | messageId: "notCamelCase", | |
754 | data: { name: "no_camelcased" }, | |
755 | type: "Identifier" | |
756 | } | |
757 | ] | |
758 | }, | |
759 | { | |
760 | code: "const { no_camelcased = foo_bar } = bar;", | |
761 | parserOptions: { ecmaVersion: 6 }, | |
762 | errors: [ | |
763 | { | |
764 | messageId: "notCamelCase", | |
765 | data: { name: "no_camelcased" }, | |
766 | type: "Identifier" | |
767 | } | |
768 | ] | |
769 | }, | |
770 | { | |
771 | code: "not_ignored_foo = 0;", | |
772 | options: [{ allow: ["ignored_bar"] }], | |
773 | errors: [ | |
774 | { | |
775 | messageId: "notCamelCase", | |
776 | data: { name: "not_ignored_foo" }, | |
777 | type: "Identifier" | |
778 | } | |
779 | ] | |
780 | }, | |
781 | { | |
782 | code: "not_ignored_foo = 0;", | |
783 | options: [{ allow: ["_id$"] }], | |
784 | errors: [ | |
785 | { | |
786 | messageId: "notCamelCase", | |
787 | data: { name: "not_ignored_foo" }, | |
788 | type: "Identifier" | |
789 | } | |
790 | ] | |
791 | }, | |
792 | { | |
793 | code: "foo = { [computed_bar]: 0 };", | |
794 | options: [{ ignoreDestructuring: true }], | |
795 | parserOptions: { ecmaVersion: 6 }, | |
796 | errors: [ | |
797 | { | |
798 | messageId: "notCamelCase", | |
799 | data: { name: "computed_bar" }, | |
800 | type: "Identifier" | |
801 | } | |
802 | ] | |
803 | }, | |
804 | { | |
805 | code: "({ a: obj.fo_o } = bar);", | |
806 | parserOptions: { ecmaVersion: 6 }, | |
807 | errors: [ | |
808 | { | |
809 | messageId: "notCamelCase", | |
810 | data: { name: "fo_o" }, | |
811 | type: "Identifier" | |
812 | } | |
813 | ] | |
814 | }, | |
815 | { | |
816 | code: "({ a: obj.fo_o } = bar);", | |
817 | options: [{ ignoreDestructuring: true }], | |
818 | parserOptions: { ecmaVersion: 6 }, | |
819 | errors: [ | |
820 | { | |
821 | messageId: "notCamelCase", | |
822 | data: { name: "fo_o" }, | |
823 | type: "Identifier" | |
824 | } | |
825 | ] | |
826 | }, | |
827 | { | |
828 | code: "({ a: obj.fo_o.b_ar } = baz);", | |
829 | parserOptions: { ecmaVersion: 6 }, | |
830 | errors: [ | |
831 | { | |
832 | messageId: "notCamelCase", | |
833 | data: { name: "b_ar" }, | |
834 | type: "Identifier" | |
835 | } | |
836 | ] | |
837 | }, | |
838 | { | |
839 | code: "({ a: { b: { c: obj.fo_o } } } = bar);", | |
840 | parserOptions: { ecmaVersion: 6 }, | |
841 | errors: [ | |
842 | { | |
843 | messageId: "notCamelCase", | |
844 | data: { name: "fo_o" }, | |
845 | type: "Identifier" | |
846 | } | |
847 | ] | |
848 | }, | |
849 | { | |
850 | code: "({ a: { b: { c: obj.fo_o.b_ar } } } = baz);", | |
851 | parserOptions: { ecmaVersion: 6 }, | |
852 | errors: [ | |
853 | { | |
854 | messageId: "notCamelCase", | |
855 | data: { name: "b_ar" }, | |
856 | type: "Identifier" | |
857 | } | |
858 | ] | |
859 | }, | |
860 | { | |
861 | code: "([obj.fo_o] = bar);", | |
862 | parserOptions: { ecmaVersion: 6 }, | |
863 | errors: [ | |
864 | { | |
865 | messageId: "notCamelCase", | |
866 | data: { name: "fo_o" }, | |
867 | type: "Identifier" | |
868 | } | |
869 | ] | |
870 | }, | |
871 | { | |
872 | code: "([obj.fo_o] = bar);", | |
873 | options: [{ ignoreDestructuring: true }], | |
874 | parserOptions: { ecmaVersion: 6 }, | |
875 | errors: [ | |
876 | { | |
877 | messageId: "notCamelCase", | |
878 | data: { name: "fo_o" }, | |
879 | type: "Identifier" | |
880 | } | |
881 | ] | |
882 | }, | |
883 | { | |
884 | code: "([obj.fo_o = 1] = bar);", | |
885 | options: [{ properties: "always" }], | |
886 | parserOptions: { ecmaVersion: 6 }, | |
887 | errors: [ | |
888 | { | |
889 | messageId: "notCamelCase", | |
890 | data: { name: "fo_o" }, | |
891 | type: "Identifier" | |
892 | } | |
893 | ] | |
894 | }, | |
895 | { | |
896 | code: "({ a: [obj.fo_o] } = bar);", | |
897 | parserOptions: { ecmaVersion: 6 }, | |
898 | errors: [ | |
899 | { | |
900 | messageId: "notCamelCase", | |
901 | data: { name: "fo_o" }, | |
902 | type: "Identifier" | |
903 | } | |
904 | ] | |
905 | }, | |
906 | { | |
907 | code: "({ a: { b: [obj.fo_o] } } = bar);", | |
908 | parserOptions: { ecmaVersion: 6 }, | |
909 | errors: [ | |
910 | { | |
911 | messageId: "notCamelCase", | |
912 | data: { name: "fo_o" }, | |
913 | type: "Identifier" | |
914 | } | |
915 | ] | |
916 | }, | |
917 | { | |
918 | code: "([obj.fo_o.ba_r] = baz);", | |
919 | parserOptions: { ecmaVersion: 6 }, | |
920 | errors: [ | |
921 | { | |
922 | messageId: "notCamelCase", | |
923 | data: { name: "ba_r" }, | |
924 | type: "Identifier" | |
925 | } | |
926 | ] | |
927 | }, | |
928 | { | |
929 | code: "({...obj.fo_o} = baz);", | |
930 | parserOptions: { ecmaVersion: 9 }, | |
931 | errors: [ | |
932 | { | |
933 | messageId: "notCamelCase", | |
934 | data: { name: "fo_o" }, | |
935 | type: "Identifier" | |
936 | } | |
937 | ] | |
938 | }, | |
939 | { | |
940 | code: "({...obj.fo_o.ba_r} = baz);", | |
941 | parserOptions: { ecmaVersion: 9 }, | |
942 | errors: [ | |
943 | { | |
944 | messageId: "notCamelCase", | |
945 | data: { name: "ba_r" }, | |
946 | type: "Identifier" | |
947 | } | |
948 | ] | |
949 | }, | |
950 | { | |
951 | code: "({c: {...obj.fo_o }} = baz);", | |
952 | parserOptions: { ecmaVersion: 9 }, | |
953 | errors: [ | |
954 | { | |
955 | messageId: "notCamelCase", | |
956 | data: { name: "fo_o" }, | |
957 | type: "Identifier" | |
958 | } | |
959 | ] | |
960 | } | |
961 | ] | |
962 | }); |