]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/sort-keys.js
import 8.23.1 source
[pve-eslint.git] / eslint / tests / lib / rules / sort-keys.js
1 /**
2 * @fileoverview Tests for sort-keys rule.
3 * @author Toru Nagashima
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/sort-keys"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("sort-keys", rule, {
22 valid: [
23
24 // default (asc)
25 { code: "var obj = {'':1, [``]:2}", options: [], parserOptions: { ecmaVersion: 6 } },
26 { code: "var obj = {[``]:1, '':2}", options: [], parserOptions: { ecmaVersion: 6 } },
27 { code: "var obj = {'':1, a:2}", options: [] },
28 { code: "var obj = {[``]:1, a:2}", options: [], parserOptions: { ecmaVersion: 6 } },
29 { code: "var obj = {_:2, a:1, b:3} // default", options: [] },
30 { code: "var obj = {a:1, b:3, c:2}", options: [] },
31 { code: "var obj = {a:2, b:3, b_:1}", options: [] },
32 { code: "var obj = {C:3, b_:1, c:2}", options: [] },
33 { code: "var obj = {$:1, A:3, _:2, a:4}", options: [] },
34 { code: "var obj = {1:1, '11':2, 2:4, A:3}", options: [] },
35 { code: "var obj = {'#':1, 'Z':2, À:3, è:4}", options: [] },
36 { code: "var obj = { [/(?<zero>0)/]: 1, '/(?<zero>0)/': 2 }", options: [], parserOptions: { ecmaVersion: 2018 } },
37
38 // ignore non-simple computed properties.
39 { code: "var obj = {a:1, b:3, [a + b]: -1, c:2}", options: [], parserOptions: { ecmaVersion: 6 } },
40 { code: "var obj = {'':1, [f()]:2, a:3}", options: [], parserOptions: { ecmaVersion: 6 } },
41 { code: "var obj = {a:1, [b++]:2, '':3}", options: ["desc"], parserOptions: { ecmaVersion: 6 } },
42
43 // ignore properties separated by spread properties
44 { code: "var obj = {a:1, ...z, b:1}", options: [], parserOptions: { ecmaVersion: 2018 } },
45 { code: "var obj = {b:1, ...z, a:1}", options: [], parserOptions: { ecmaVersion: 2018 } },
46 { code: "var obj = {...a, b:1, ...c, d:1}", options: [], parserOptions: { ecmaVersion: 2018 } },
47 { code: "var obj = {...a, b:1, ...d, ...c, e:2, z:5}", options: [], parserOptions: { ecmaVersion: 2018 } },
48 { code: "var obj = {b:1, ...c, ...d, e:2}", options: [], parserOptions: { ecmaVersion: 2018 } },
49 { code: "var obj = {a:1, ...z, '':2}", options: [], parserOptions: { ecmaVersion: 2018 } },
50 { code: "var obj = {'':1, ...z, 'a':2}", options: ["desc"], parserOptions: { ecmaVersion: 2018 } },
51
52 // not ignore properties not separated by spread properties
53 { code: "var obj = {...z, a:1, b:1}", options: [], parserOptions: { ecmaVersion: 2018 } },
54 { code: "var obj = {...z, ...c, a:1, b:1}", options: [], parserOptions: { ecmaVersion: 2018 } },
55 { code: "var obj = {a:1, b:1, ...z}", options: [], parserOptions: { ecmaVersion: 2018 } },
56 { code: "var obj = {...z, ...x, a:1, ...c, ...d, f:5, e:4}", options: ["desc"], parserOptions: { ecmaVersion: 2018 } },
57
58 // works when spread occurs somewhere other than an object literal
59 { code: "function fn(...args) { return [...args].length; }", options: [], parserOptions: { ecmaVersion: 2018 } },
60 { code: "function g() {}; function f(...args) { return g(...args); }", options: [], parserOptions: { ecmaVersion: 2018 } },
61
62 // ignore destructuring patterns.
63 { code: "let {a, b} = {}", options: [], parserOptions: { ecmaVersion: 6 } },
64
65 // nested
66 { code: "var obj = {a:1, b:{x:1, y:1}, c:1}", options: [] },
67
68 // asc
69 { code: "var obj = {_:2, a:1, b:3} // asc", options: ["asc"] },
70 { code: "var obj = {a:1, b:3, c:2}", options: ["asc"] },
71 { code: "var obj = {a:2, b:3, b_:1}", options: ["asc"] },
72 { code: "var obj = {C:3, b_:1, c:2}", options: ["asc"] },
73 { code: "var obj = {$:1, A:3, _:2, a:4}", options: ["asc"] },
74 { code: "var obj = {1:1, '11':2, 2:4, A:3}", options: ["asc"] },
75 { code: "var obj = {'#':1, 'Z':2, À:3, è:4}", options: ["asc"] },
76
77 // asc, minKeys should ignore unsorted keys when number of keys is less than minKeys
78 { code: "var obj = {a:1, c:2, b:3}", options: ["asc", { minKeys: 4 }] },
79
80 // asc, insensitive
81 { code: "var obj = {_:2, a:1, b:3} // asc, insensitive", options: ["asc", { caseSensitive: false }] },
82 { code: "var obj = {a:1, b:3, c:2}", options: ["asc", { caseSensitive: false }] },
83 { code: "var obj = {a:2, b:3, b_:1}", options: ["asc", { caseSensitive: false }] },
84 { code: "var obj = {b_:1, C:3, c:2}", options: ["asc", { caseSensitive: false }] },
85 { code: "var obj = {b_:1, c:3, C:2}", options: ["asc", { caseSensitive: false }] },
86 { code: "var obj = {$:1, _:2, A:3, a:4}", options: ["asc", { caseSensitive: false }] },
87 { code: "var obj = {1:1, '11':2, 2:4, A:3}", options: ["asc", { caseSensitive: false }] },
88 { code: "var obj = {'#':1, 'Z':2, À:3, è:4}", options: ["asc", { caseSensitive: false }] },
89
90 // asc, insensitive, minKeys should ignore unsorted keys when number of keys is less than minKeys
91 { code: "var obj = {$:1, A:3, _:2, a:4}", options: ["asc", { caseSensitive: false, minKeys: 5 }] },
92
93 // asc, natural
94 { code: "var obj = {_:2, a:1, b:3} // asc, natural", options: ["asc", { natural: true }] },
95 { code: "var obj = {a:1, b:3, c:2}", options: ["asc", { natural: true }] },
96 { code: "var obj = {a:2, b:3, b_:1}", options: ["asc", { natural: true }] },
97 { code: "var obj = {C:3, b_:1, c:2}", options: ["asc", { natural: true }] },
98 { code: "var obj = {$:1, _:2, A:3, a:4}", options: ["asc", { natural: true }] },
99 { code: "var obj = {1:1, 2:4, '11':2, A:3}", options: ["asc", { natural: true }] },
100 { code: "var obj = {'#':1, 'Z':2, À:3, è:4}", options: ["asc", { natural: true }] },
101
102 // asc, natural, minKeys should ignore unsorted keys when number of keys is less than minKeys
103 { code: "var obj = {b_:1, a:2, b:3}", options: ["asc", { natural: true, minKeys: 4 }] },
104
105 // asc, natural, insensitive
106 { code: "var obj = {_:2, a:1, b:3} // asc, natural, insensitive", options: ["asc", { natural: true, caseSensitive: false }] },
107 { code: "var obj = {a:1, b:3, c:2}", options: ["asc", { natural: true, caseSensitive: false }] },
108 { code: "var obj = {a:2, b:3, b_:1}", options: ["asc", { natural: true, caseSensitive: false }] },
109 { code: "var obj = {b_:1, C:3, c:2}", options: ["asc", { natural: true, caseSensitive: false }] },
110 { code: "var obj = {b_:1, c:3, C:2}", options: ["asc", { natural: true, caseSensitive: false }] },
111 { code: "var obj = {$:1, _:2, A:3, a:4}", options: ["asc", { natural: true, caseSensitive: false }] },
112 { code: "var obj = {1:1, 2:4, '11':2, A:3}", options: ["asc", { natural: true, caseSensitive: false }] },
113 { code: "var obj = {'#':1, 'Z':2, À:3, è:4}", options: ["asc", { natural: true, caseSensitive: false }] },
114
115 // asc, natural, insensitive, minKeys should ignore unsorted keys when number of keys is less than minKeys
116 { code: "var obj = {a:1, _:2, b:3}", options: ["asc", { natural: true, caseSensitive: false, minKeys: 4 }] },
117
118 // desc
119 { code: "var obj = {b:3, a:1, _:2} // desc", options: ["desc"] },
120 { code: "var obj = {c:2, b:3, a:1}", options: ["desc"] },
121 { code: "var obj = {b_:1, b:3, a:2}", options: ["desc"] },
122 { code: "var obj = {c:2, b_:1, C:3}", options: ["desc"] },
123 { code: "var obj = {a:4, _:2, A:3, $:1}", options: ["desc"] },
124 { code: "var obj = {A:3, 2:4, '11':2, 1:1}", options: ["desc"] },
125 { code: "var obj = {è:4, À:3, 'Z':2, '#':1}", options: ["desc"] },
126
127 // desc, minKeys should ignore unsorted keys when number of keys is less than minKeys
128 { code: "var obj = {a:1, c:2, b:3}", options: ["desc", { minKeys: 4 }] },
129
130 // desc, insensitive
131 { code: "var obj = {b:3, a:1, _:2} // desc, insensitive", options: ["desc", { caseSensitive: false }] },
132 { code: "var obj = {c:2, b:3, a:1}", options: ["desc", { caseSensitive: false }] },
133 { code: "var obj = {b_:1, b:3, a:2}", options: ["desc", { caseSensitive: false }] },
134 { code: "var obj = {c:2, C:3, b_:1}", options: ["desc", { caseSensitive: false }] },
135 { code: "var obj = {C:2, c:3, b_:1}", options: ["desc", { caseSensitive: false }] },
136 { code: "var obj = {a:4, A:3, _:2, $:1}", options: ["desc", { caseSensitive: false }] },
137 { code: "var obj = {A:3, 2:4, '11':2, 1:1}", options: ["desc", { caseSensitive: false }] },
138 { code: "var obj = {è:4, À:3, 'Z':2, '#':1}", options: ["desc", { caseSensitive: false }] },
139
140 // desc, insensitive, minKeys should ignore unsorted keys when number of keys is less than minKeys
141 { code: "var obj = {$:1, _:2, A:3, a:4}", options: ["desc", { caseSensitive: false, minKeys: 5 }] },
142
143 // desc, natural
144 { code: "var obj = {b:3, a:1, _:2} // desc, natural", options: ["desc", { natural: true }] },
145 { code: "var obj = {c:2, b:3, a:1}", options: ["desc", { natural: true }] },
146 { code: "var obj = {b_:1, b:3, a:2}", options: ["desc", { natural: true }] },
147 { code: "var obj = {c:2, b_:1, C:3}", options: ["desc", { natural: true }] },
148 { code: "var obj = {a:4, A:3, _:2, $:1}", options: ["desc", { natural: true }] },
149 { code: "var obj = {A:3, '11':2, 2:4, 1:1}", options: ["desc", { natural: true }] },
150 { code: "var obj = {è:4, À:3, 'Z':2, '#':1}", options: ["desc", { natural: true }] },
151
152 // desc, natural, minKeys should ignore unsorted keys when number of keys is less than minKeys
153 { code: "var obj = {b_:1, a:2, b:3}", options: ["desc", { natural: true, minKeys: 4 }] },
154
155 // desc, natural, insensitive
156 { code: "var obj = {b:3, a:1, _:2} // desc, natural, insensitive", options: ["desc", { natural: true, caseSensitive: false }] },
157 { code: "var obj = {c:2, b:3, a:1}", options: ["desc", { natural: true, caseSensitive: false }] },
158 { code: "var obj = {b_:1, b:3, a:2}", options: ["desc", { natural: true, caseSensitive: false }] },
159 { code: "var obj = {c:2, C:3, b_:1}", options: ["desc", { natural: true, caseSensitive: false }] },
160 { code: "var obj = {C:2, c:3, b_:1}", options: ["desc", { natural: true, caseSensitive: false }] },
161 { code: "var obj = {a:4, A:3, _:2, $:1}", options: ["desc", { natural: true, caseSensitive: false }] },
162 { code: "var obj = {A:3, '11':2, 2:4, 1:1}", options: ["desc", { natural: true, caseSensitive: false }] },
163 { code: "var obj = {è:4, À:3, 'Z':2, '#':1}", options: ["desc", { natural: true, caseSensitive: false }] },
164
165 // desc, natural, insensitive, minKeys should ignore unsorted keys when number of keys is less than minKeys
166 { code: "var obj = {a:1, _:2, b:3}", options: ["desc", { natural: true, caseSensitive: false, minKeys: 4 }] },
167
168 // allowLineSeparatedGroups option
169 {
170 code: `
171 var obj = {
172 e: 1,
173 f: 2,
174 g: 3,
175
176 a: 4,
177 b: 5,
178 c: 6
179 }
180 `,
181 options: ["asc", { allowLineSeparatedGroups: true }]
182 },
183 {
184 code: `
185 var obj = {
186 b: 1,
187
188 // comment
189 a: 2,
190 c: 3
191 }
192 `,
193 options: ["asc", { allowLineSeparatedGroups: true }]
194 },
195 {
196 code: `
197 var obj = {
198 b: 1
199
200 ,
201
202 // comment
203 a: 2,
204 c: 3
205 }
206 `,
207 options: ["asc", { allowLineSeparatedGroups: true }]
208 },
209 {
210 code: `
211 var obj = {
212 c: 1,
213 d: 2,
214
215 b() {
216 },
217 e: 4
218 }
219 `,
220 options: ["asc", { allowLineSeparatedGroups: true }],
221 parserOptions: { ecmaVersion: 6 }
222 },
223 {
224 code: `
225 var obj = {
226 c: 1,
227 d: 2,
228 // comment
229
230 // comment
231 b() {
232 },
233 e: 4
234 }
235 `,
236 options: ["asc", { allowLineSeparatedGroups: true }],
237 parserOptions: { ecmaVersion: 6 }
238 },
239 {
240 code: `
241 var obj = {
242 b,
243
244 [a+b]: 1,
245 a
246 }
247 `,
248 options: ["asc", { allowLineSeparatedGroups: true }],
249 parserOptions: { ecmaVersion: 6 }
250 },
251 {
252 code: `
253 var obj = {
254 c: 1,
255 d: 2,
256
257 a() {
258
259 },
260
261 // abce
262 f: 3,
263
264 /*
265
266 */
267 [a+b]: 1,
268 cc: 1,
269 e: 2
270 }
271 `,
272 options: ["asc", { allowLineSeparatedGroups: true }],
273 parserOptions: { ecmaVersion: 6 }
274 },
275 {
276 code: `
277 var obj = {
278 b: "/*",
279
280 a: "*/",
281 }
282 `,
283 options: ["asc", { allowLineSeparatedGroups: true }]
284 },
285 {
286 code: `
287 var obj = {
288 b,
289 /*
290 */ //
291
292 a
293 }
294 `,
295 options: ["asc", { allowLineSeparatedGroups: true }],
296 parserOptions: { ecmaVersion: 6 }
297 },
298 {
299 code: `
300 var obj = {
301 b,
302
303 /*
304 */ //
305 a
306 }
307 `,
308 options: ["asc", { allowLineSeparatedGroups: true }],
309 parserOptions: { ecmaVersion: 6 }
310 },
311 {
312 code: `
313 var obj = {
314 b: 1
315
316 ,a: 2
317 };
318 `,
319 options: ["asc", { allowLineSeparatedGroups: true }],
320 parserOptions: { ecmaVersion: 6 }
321 },
322 {
323 code: `
324 var obj = {
325 b: 1
326 // comment before comma
327
328 ,
329 a: 2
330 };
331 `,
332 options: ["asc", { allowLineSeparatedGroups: true }],
333 parserOptions: { ecmaVersion: 6 }
334 },
335 {
336 code: `
337 var obj = {
338 b,
339
340 a,
341 ...z,
342 c
343 }
344 `,
345 options: ["asc", { allowLineSeparatedGroups: true }],
346 parserOptions: { ecmaVersion: 2018 }
347 },
348 {
349 code: `
350 var obj = {
351 b,
352
353 [foo()]: [
354
355 ],
356 a
357 }
358 `,
359 options: ["asc", { allowLineSeparatedGroups: true }],
360 parserOptions: { ecmaVersion: 2018 }
361 }
362 ],
363 invalid: [
364
365 // default (asc)
366 {
367 code: "var obj = {a:1, '':2} // default",
368 errors: [
369 {
370 messageId: "sortKeys",
371 data: {
372 natural: "",
373 insensitive: "",
374 order: "asc",
375 thisName: "",
376 prevName: "a"
377 }
378 }
379 ]
380 },
381 {
382 code: "var obj = {a:1, [``]:2} // default",
383 parserOptions: { ecmaVersion: 6 },
384 errors: [
385 {
386 messageId: "sortKeys",
387 data: {
388 natural: "",
389 insensitive: "",
390 order: "asc",
391 thisName: "",
392 prevName: "a"
393 }
394 }
395 ]
396 },
397 {
398 code: "var obj = {a:1, _:2, b:3} // default",
399 errors: [
400 {
401 messageId: "sortKeys",
402 data: {
403 natural: "",
404 insensitive: "",
405 order: "asc",
406 thisName: "_",
407 prevName: "a"
408 }
409 }
410 ]
411 },
412 {
413 code: "var obj = {a:1, c:2, b:3}",
414 errors: [
415 {
416 messageId: "sortKeys",
417 data: {
418 natural: "",
419 insensitive: "",
420 order: "asc",
421 thisName: "b",
422 prevName: "c"
423 }
424 }
425 ]
426 },
427 {
428 code: "var obj = {b_:1, a:2, b:3}",
429 errors: [
430 {
431 messageId: "sortKeys",
432 data: {
433 natural: "",
434 insensitive: "",
435 order: "asc",
436 thisName: "a",
437 prevName: "b_"
438 }
439 }
440 ]
441 },
442 {
443 code: "var obj = {b_:1, c:2, C:3}",
444 errors: [
445 {
446 messageId: "sortKeys",
447 data: {
448 natural: "",
449 insensitive: "",
450 order: "asc",
451 thisName: "C",
452 prevName: "c"
453 }
454 }
455 ]
456 },
457 {
458 code: "var obj = {$:1, _:2, A:3, a:4}",
459 errors: [
460 {
461 messageId: "sortKeys",
462 data: {
463 natural: "",
464 insensitive: "",
465 order: "asc",
466 thisName: "A",
467 prevName: "_"
468 }
469 }
470 ]
471 },
472 {
473 code: "var obj = {1:1, 2:4, A:3, '11':2}",
474 errors: [
475 {
476 messageId: "sortKeys",
477 data: {
478 natural: "",
479 insensitive: "",
480 order: "asc",
481 thisName: "11",
482 prevName: "A"
483 }
484 }
485 ]
486 },
487 {
488 code: "var obj = {'#':1, À:3, 'Z':2, è:4}",
489 errors: [
490 {
491 messageId: "sortKeys",
492 data: {
493 natural: "",
494 insensitive: "",
495 order: "asc",
496 thisName: "Z",
497 prevName: "À"
498 }
499 }
500 ]
501 },
502 {
503 code: "var obj = { null: 1, [/(?<zero>0)/]: 2 }",
504 parserOptions: { ecmaVersion: 2018 },
505 errors: [
506 {
507 messageId: "sortKeys",
508 data: {
509 natural: "",
510 insensitive: "",
511 order: "asc",
512 thisName: "/(?<zero>0)/",
513 prevName: "null"
514 }
515 }
516 ]
517 },
518
519 // not ignore properties not separated by spread properties
520 {
521 code: "var obj = {...z, c:1, b:1}",
522 options: [],
523 parserOptions: { ecmaVersion: 2018 },
524 errors: [
525 {
526 messageId: "sortKeys",
527 data: {
528 natural: "",
529 insensitive: "",
530 order: "asc",
531 thisName: "b",
532 prevName: "c"
533 }
534 }
535 ]
536 },
537 {
538 code: "var obj = {...z, ...c, d:4, b:1, ...y, ...f, e:2, a:1}",
539 options: [],
540 parserOptions: { ecmaVersion: 2018 },
541 errors: [
542 {
543 messageId: "sortKeys",
544 data: {
545 natural: "",
546 insensitive: "",
547 order: "asc",
548 thisName: "b",
549 prevName: "d"
550 }
551 },
552 {
553 messageId: "sortKeys",
554 data: {
555 natural: "",
556 insensitive: "",
557 order: "asc",
558 thisName: "a",
559 prevName: "e"
560 }
561 }
562 ]
563 },
564 {
565 code: "var obj = {c:1, b:1, ...a}",
566 options: [],
567 parserOptions: { ecmaVersion: 2018 },
568 errors: [
569 {
570 messageId: "sortKeys",
571 data: {
572 natural: "",
573 insensitive: "",
574 order: "asc",
575 thisName: "b",
576 prevName: "c"
577 }
578 }
579 ]
580 },
581 {
582 code: "var obj = {...z, ...a, c:1, b:1}",
583 options: [],
584 parserOptions: { ecmaVersion: 2018 },
585 errors: [
586 {
587 messageId: "sortKeys",
588 data: {
589 natural: "",
590 insensitive: "",
591 order: "asc",
592 thisName: "b",
593 prevName: "c"
594 }
595 }
596 ]
597 },
598 {
599 code: "var obj = {...z, b:1, a:1, ...d, ...c}",
600 options: [],
601 parserOptions: { ecmaVersion: 2018 },
602 errors: [
603 {
604 messageId: "sortKeys",
605 data: {
606 natural: "",
607 insensitive: "",
608 order: "asc",
609 thisName: "a",
610 prevName: "b"
611 }
612 }
613 ]
614 },
615 {
616 code: "var obj = {...z, a:2, b:0, ...x, ...c}",
617 options: ["desc"],
618 parserOptions: { ecmaVersion: 2018 },
619 errors: [
620 {
621 messageId: "sortKeys",
622 data: {
623 natural: "",
624 insensitive: "",
625 order: "desc",
626 thisName: "b",
627 prevName: "a"
628 }
629 }
630 ]
631 },
632 {
633 code: "var obj = {...z, a:2, b:0, ...x}",
634 options: ["desc"],
635 parserOptions: { ecmaVersion: 2018 },
636 errors: [
637 {
638 messageId: "sortKeys",
639 data: {
640 natural: "",
641 insensitive: "",
642 order: "desc",
643 thisName: "b",
644 prevName: "a"
645 }
646 }
647 ]
648 },
649 {
650 code: "var obj = {...z, '':1, a:2}",
651 options: ["desc"],
652 parserOptions: { ecmaVersion: 2018 },
653 errors: [
654 {
655 messageId: "sortKeys",
656 data: {
657 natural: "",
658 insensitive: "",
659 order: "desc",
660 thisName: "a",
661 prevName: ""
662 }
663 }
664 ]
665 },
666
667 // ignore non-simple computed properties, but their position shouldn't affect other comparisons.
668 {
669 code: "var obj = {a:1, [b+c]:2, '':3}",
670 parserOptions: { ecmaVersion: 6 },
671 errors: [
672 {
673 messageId: "sortKeys",
674 data: {
675 natural: "",
676 insensitive: "",
677 order: "asc",
678 thisName: "",
679 prevName: "a"
680 }
681 }
682 ]
683 },
684 {
685 code: "var obj = {'':1, [b+c]:2, a:3}",
686 options: ["desc"],
687 parserOptions: { ecmaVersion: 6 },
688 errors: [
689 {
690 messageId: "sortKeys",
691 data: {
692 natural: "",
693 insensitive: "",
694 order: "desc",
695 thisName: "a",
696 prevName: ""
697 }
698 }
699 ]
700 },
701 {
702 code: "var obj = {b:1, [f()]:2, '':3, a:4}",
703 options: ["desc"],
704 parserOptions: { ecmaVersion: 6 },
705 errors: [
706 {
707 messageId: "sortKeys",
708 data: {
709 natural: "",
710 insensitive: "",
711 order: "desc",
712 thisName: "a",
713 prevName: ""
714 }
715 }
716 ]
717 },
718
719 // not ignore simple computed properties.
720 {
721 code: "var obj = {a:1, b:3, [a]: -1, c:2}",
722 parserOptions: { ecmaVersion: 6 },
723 errors: [
724 {
725 messageId: "sortKeys",
726 data: {
727 natural: "",
728 insensitive: "",
729 order: "asc",
730 thisName: "a",
731 prevName: "b"
732 }
733 }
734 ]
735 },
736
737 // nested
738 {
739 code: "var obj = {a:1, c:{y:1, x:1}, b:1}",
740 errors: [
741 {
742 messageId: "sortKeys",
743 data: {
744 natural: "",
745 insensitive: "",
746 order: "asc",
747 thisName: "x",
748 prevName: "y"
749 }
750 },
751 {
752 messageId: "sortKeys",
753 data: {
754 natural: "",
755 insensitive: "",
756 order: "asc",
757 thisName: "b",
758 prevName: "c"
759 }
760 }
761 ]
762 },
763
764 // asc
765 {
766 code: "var obj = {a:1, _:2, b:3} // asc",
767 options: ["asc"],
768 errors: [
769 {
770 messageId: "sortKeys",
771 data: {
772 natural: "",
773 insensitive: "",
774 order: "asc",
775 thisName: "_",
776 prevName: "a"
777 }
778 }
779 ]
780 },
781 {
782 code: "var obj = {a:1, c:2, b:3}",
783 options: ["asc"],
784 errors: [
785 {
786 messageId: "sortKeys",
787 data: {
788 natural: "",
789 insensitive: "",
790 order: "asc",
791 thisName: "b",
792 prevName: "c"
793 }
794 }
795 ]
796 },
797 {
798 code: "var obj = {b_:1, a:2, b:3}",
799 options: ["asc"],
800 errors: [
801 {
802 messageId: "sortKeys",
803 data: {
804 natural: "",
805 insensitive: "",
806 order: "asc",
807 thisName: "a",
808 prevName: "b_"
809 }
810 }
811 ]
812 },
813 {
814 code: "var obj = {b_:1, c:2, C:3}",
815 options: ["asc"],
816 errors: [
817 {
818 messageId: "sortKeys",
819 data: {
820 natural: "",
821 insensitive: "",
822 order: "asc",
823 thisName: "C",
824 prevName: "c"
825 }
826 }
827 ]
828 },
829 {
830 code: "var obj = {$:1, _:2, A:3, a:4}",
831 options: ["asc"],
832 errors: [
833 {
834 messageId: "sortKeys",
835 data: {
836 natural: "",
837 insensitive: "",
838 order: "asc",
839 thisName: "A",
840 prevName: "_"
841 }
842 }
843 ]
844 },
845 {
846 code: "var obj = {1:1, 2:4, A:3, '11':2}",
847 options: ["asc"],
848 errors: [
849 {
850 messageId: "sortKeys",
851 data: {
852 natural: "",
853 insensitive: "",
854 order: "asc",
855 thisName: "11",
856 prevName: "A"
857 }
858 }
859 ]
860 },
861 {
862 code: "var obj = {'#':1, À:3, 'Z':2, è:4}",
863 options: ["asc"],
864 errors: [
865 {
866 messageId: "sortKeys",
867 data: {
868 natural: "",
869 insensitive: "",
870 order: "asc",
871 thisName: "Z",
872 prevName: "À"
873 }
874 }
875 ]
876 },
877
878 // asc, minKeys should error when number of keys is greater than or equal to minKeys
879 {
880 code: "var obj = {a:1, _:2, b:3}",
881 options: ["asc", { minKeys: 3 }],
882 errors: [
883 {
884 messageId: "sortKeys",
885 data: {
886 natural: "",
887 insensitive: "",
888 order: "asc",
889 thisName: "_",
890 prevName: "a"
891 }
892 }
893 ]
894 },
895
896 // asc, insensitive
897 {
898 code: "var obj = {a:1, _:2, b:3} // asc, insensitive",
899 options: ["asc", { caseSensitive: false }],
900 errors: [
901 {
902 messageId: "sortKeys",
903 data: {
904 natural: "",
905 insensitive: "insensitive ",
906 order: "asc",
907 thisName: "_",
908 prevName: "a"
909 }
910 }
911 ]
912 },
913 {
914 code: "var obj = {a:1, c:2, b:3}",
915 options: ["asc", { caseSensitive: false }],
916 errors: [
917 {
918 messageId: "sortKeys",
919 data: {
920 natural: "",
921 insensitive: "insensitive ",
922 order: "asc",
923 thisName: "b",
924 prevName: "c"
925 }
926 }
927 ]
928 },
929 {
930 code: "var obj = {b_:1, a:2, b:3}",
931 options: ["asc", { caseSensitive: false }],
932 errors: [
933 {
934 messageId: "sortKeys",
935 data: {
936 natural: "",
937 insensitive: "insensitive ",
938 order: "asc",
939 thisName: "a",
940 prevName: "b_"
941 }
942 }
943 ]
944 },
945 {
946 code: "var obj = {$:1, A:3, _:2, a:4}",
947 options: ["asc", { caseSensitive: false }],
948 errors: [
949 {
950 messageId: "sortKeys",
951 data: {
952 natural: "",
953 insensitive: "insensitive ",
954 order: "asc",
955 thisName: "_",
956 prevName: "A"
957 }
958 }
959 ]
960 },
961 {
962 code: "var obj = {1:1, 2:4, A:3, '11':2}",
963 options: ["asc", { caseSensitive: false }],
964 errors: [
965 {
966 messageId: "sortKeys",
967 data: {
968 natural: "",
969 insensitive: "insensitive ",
970 order: "asc",
971 thisName: "11",
972 prevName: "A"
973 }
974 }
975 ]
976 },
977 {
978 code: "var obj = {'#':1, À:3, 'Z':2, è:4}",
979 options: ["asc", { caseSensitive: false }],
980 errors: [
981 {
982 messageId: "sortKeys",
983 data: {
984 natural: "",
985 insensitive: "insensitive ",
986 order: "asc",
987 thisName: "Z",
988 prevName: "À"
989 }
990 }
991 ]
992 },
993
994 // asc, insensitive, minKeys should error when number of keys is greater than or equal to minKeys
995 {
996 code: "var obj = {a:1, _:2, b:3}",
997 options: ["asc", { caseSensitive: false, minKeys: 3 }],
998 errors: [
999 {
1000 messageId: "sortKeys",
1001 data: {
1002 natural: "",
1003 insensitive: "insensitive ",
1004 order: "asc",
1005 thisName: "_",
1006 prevName: "a"
1007 }
1008 }
1009 ]
1010 },
1011
1012 // asc, natural
1013 {
1014 code: "var obj = {a:1, _:2, b:3} // asc, natural",
1015 options: ["asc", { natural: true }],
1016 errors: [
1017 {
1018 messageId: "sortKeys",
1019 data: {
1020 natural: "natural ",
1021 insensitive: "",
1022 order: "asc",
1023 thisName: "_",
1024 prevName: "a"
1025 }
1026 }
1027 ]
1028 },
1029 {
1030 code: "var obj = {a:1, c:2, b:3}",
1031 options: ["asc", { natural: true }],
1032 errors: [
1033 {
1034 messageId: "sortKeys",
1035 data: {
1036 natural: "natural ",
1037 insensitive: "",
1038 order: "asc",
1039 thisName: "b",
1040 prevName: "c"
1041 }
1042 }
1043 ]
1044 },
1045 {
1046 code: "var obj = {b_:1, a:2, b:3}",
1047 options: ["asc", { natural: true }],
1048 errors: [
1049 {
1050 messageId: "sortKeys",
1051 data: {
1052 natural: "natural ",
1053 insensitive: "",
1054 order: "asc",
1055 thisName: "a",
1056 prevName: "b_"
1057 }
1058 }
1059 ]
1060 },
1061 {
1062 code: "var obj = {b_:1, c:2, C:3}",
1063 options: ["asc", { natural: true }],
1064 errors: [
1065 {
1066 messageId: "sortKeys",
1067 data: {
1068 natural: "natural ",
1069 insensitive: "",
1070 order: "asc",
1071 thisName: "C",
1072 prevName: "c"
1073 }
1074 }
1075 ]
1076 },
1077 {
1078 code: "var obj = {$:1, A:3, _:2, a:4}",
1079 options: ["asc", { natural: true }],
1080 errors: [
1081 {
1082 messageId: "sortKeys",
1083 data: {
1084 natural: "natural ",
1085 insensitive: "",
1086 order: "asc",
1087 thisName: "_",
1088 prevName: "A"
1089 }
1090 }
1091 ]
1092 },
1093 {
1094 code: "var obj = {1:1, 2:4, A:3, '11':2}",
1095 options: ["asc", { natural: true }],
1096 errors: [
1097 {
1098 messageId: "sortKeys",
1099 data: {
1100 natural: "natural ",
1101 insensitive: "",
1102 order: "asc",
1103 thisName: "11",
1104 prevName: "A"
1105 }
1106 }
1107 ]
1108 },
1109 {
1110 code: "var obj = {'#':1, À:3, 'Z':2, è:4}",
1111 options: ["asc", { natural: true }],
1112 errors: [
1113 {
1114 messageId: "sortKeys",
1115 data: {
1116 natural: "natural ",
1117 insensitive: "",
1118 order: "asc",
1119 thisName: "Z",
1120 prevName: "À"
1121 }
1122 }
1123 ]
1124 },
1125
1126 // asc, natural, minKeys should error when number of keys is greater than or equal to minKeys
1127 {
1128 code: "var obj = {a:1, _:2, b:3}",
1129 options: ["asc", { natural: true, minKeys: 2 }],
1130 errors: [
1131 {
1132 messageId: "sortKeys",
1133 data: {
1134 natural: "natural ",
1135 insensitive: "",
1136 order: "asc",
1137 thisName: "_",
1138 prevName: "a"
1139 }
1140 }
1141 ]
1142 },
1143
1144 // asc, natural, insensitive
1145 {
1146 code: "var obj = {a:1, _:2, b:3} // asc, natural, insensitive",
1147 options: ["asc", { natural: true, caseSensitive: false }],
1148 errors: [
1149 {
1150 messageId: "sortKeys",
1151 data: {
1152 natural: "natural ",
1153 insensitive: "insensitive ",
1154 order: "asc",
1155 thisName: "_",
1156 prevName: "a"
1157 }
1158 }
1159 ]
1160 },
1161 {
1162 code: "var obj = {a:1, c:2, b:3}",
1163 options: ["asc", { natural: true, caseSensitive: false }],
1164 errors: [
1165 {
1166 messageId: "sortKeys",
1167 data: {
1168 natural: "natural ",
1169 insensitive: "insensitive ",
1170 order: "asc",
1171 thisName: "b",
1172 prevName: "c"
1173 }
1174 }
1175 ]
1176 },
1177 {
1178 code: "var obj = {b_:1, a:2, b:3}",
1179 options: ["asc", { natural: true, caseSensitive: false }],
1180 errors: [
1181 {
1182 messageId: "sortKeys",
1183 data: {
1184 natural: "natural ",
1185 insensitive: "insensitive ",
1186 order: "asc",
1187 thisName: "a",
1188 prevName: "b_"
1189 }
1190 }
1191 ]
1192 },
1193 {
1194 code: "var obj = {$:1, A:3, _:2, a:4}",
1195 options: ["asc", { natural: true, caseSensitive: false }],
1196 errors: [
1197 {
1198 messageId: "sortKeys",
1199 data: {
1200 natural: "natural ",
1201 insensitive: "insensitive ",
1202 order: "asc",
1203 thisName: "_",
1204 prevName: "A"
1205 }
1206 }
1207 ]
1208 },
1209 {
1210 code: "var obj = {1:1, '11':2, 2:4, A:3}",
1211 options: ["asc", { natural: true, caseSensitive: false }],
1212 errors: [
1213 {
1214 messageId: "sortKeys",
1215 data: {
1216 natural: "natural ",
1217 insensitive: "insensitive ",
1218 order: "asc",
1219 thisName: "2",
1220 prevName: "11"
1221 }
1222 }
1223 ]
1224 },
1225 {
1226 code: "var obj = {'#':1, À:3, 'Z':2, è:4}",
1227 options: ["asc", { natural: true, caseSensitive: false }],
1228 errors: [
1229 {
1230 messageId: "sortKeys",
1231 data: {
1232 natural: "natural ",
1233 insensitive: "insensitive ",
1234 order: "asc",
1235 thisName: "Z",
1236 prevName: "À"
1237 }
1238 }
1239 ]
1240 },
1241
1242 // asc, natural, insensitive, minKeys should error when number of keys is greater than or equal to minKeys
1243 {
1244 code: "var obj = {a:1, _:2, b:3}",
1245 options: ["asc", { natural: true, caseSensitive: false, minKeys: 3 }],
1246 errors: [
1247 {
1248 messageId: "sortKeys",
1249 data: {
1250 natural: "natural ",
1251 insensitive: "insensitive ",
1252 order: "asc",
1253 thisName: "_",
1254 prevName: "a"
1255 }
1256 }
1257 ]
1258 },
1259
1260 // desc
1261 {
1262 code: "var obj = {'':1, a:'2'} // desc",
1263 options: ["desc"],
1264 errors: [
1265 {
1266 messageId: "sortKeys",
1267 data: {
1268 natural: "",
1269 insensitive: "",
1270 order: "desc",
1271 thisName: "a",
1272 prevName: ""
1273 }
1274 }
1275 ]
1276 },
1277 {
1278 code: "var obj = {[``]:1, a:'2'} // desc",
1279 options: ["desc"],
1280 parserOptions: { ecmaVersion: 6 },
1281 errors: [
1282 {
1283 messageId: "sortKeys",
1284 data: {
1285 natural: "",
1286 insensitive: "",
1287 order: "desc",
1288 thisName: "a",
1289 prevName: ""
1290 }
1291 }
1292 ]
1293 },
1294 {
1295 code: "var obj = {a:1, _:2, b:3} // desc",
1296 options: ["desc"],
1297 errors: [
1298 {
1299 messageId: "sortKeys",
1300 data: {
1301 natural: "",
1302 insensitive: "",
1303 order: "desc",
1304 thisName: "b",
1305 prevName: "_"
1306 }
1307 }
1308 ]
1309 },
1310 {
1311 code: "var obj = {a:1, c:2, b:3}",
1312 options: ["desc"],
1313 errors: [
1314 {
1315 messageId: "sortKeys",
1316 data: {
1317 natural: "",
1318 insensitive: "",
1319 order: "desc",
1320 thisName: "c",
1321 prevName: "a"
1322 }
1323 }
1324 ]
1325 },
1326 {
1327 code: "var obj = {b_:1, a:2, b:3}",
1328 options: ["desc"],
1329 errors: [
1330 {
1331 messageId: "sortKeys",
1332 data: {
1333 natural: "",
1334 insensitive: "",
1335 order: "desc",
1336 thisName: "b",
1337 prevName: "a"
1338 }
1339 }
1340 ]
1341 },
1342 {
1343 code: "var obj = {b_:1, c:2, C:3}",
1344 options: ["desc"],
1345 errors: [
1346 {
1347 messageId: "sortKeys",
1348 data: {
1349 natural: "",
1350 insensitive: "",
1351 order: "desc",
1352 thisName: "c",
1353 prevName: "b_"
1354 }
1355 }
1356 ]
1357 },
1358 {
1359 code: "var obj = {$:1, _:2, A:3, a:4}",
1360 options: ["desc"],
1361 errors: [
1362 {
1363 messageId: "sortKeys",
1364 data: {
1365 natural: "",
1366 insensitive: "",
1367 order: "desc",
1368 thisName: "_",
1369 prevName: "$"
1370 }
1371 },
1372 {
1373 messageId: "sortKeys",
1374 data: {
1375 natural: "",
1376 insensitive: "",
1377 order: "desc",
1378 thisName: "a",
1379 prevName: "A"
1380 }
1381 }
1382 ]
1383 },
1384 {
1385 code: "var obj = {1:1, 2:4, A:3, '11':2}",
1386 options: ["desc"],
1387 errors: [
1388 {
1389 messageId: "sortKeys",
1390 data: {
1391 natural: "",
1392 insensitive: "",
1393 order: "desc",
1394 thisName: "2",
1395 prevName: "1"
1396 }
1397 },
1398 {
1399 messageId: "sortKeys",
1400 data: {
1401 natural: "",
1402 insensitive: "",
1403 order: "desc",
1404 thisName: "A",
1405 prevName: "2"
1406 }
1407 }
1408 ]
1409 },
1410 {
1411 code: "var obj = {'#':1, À:3, 'Z':2, è:4}",
1412 options: ["desc"],
1413 errors: [
1414 {
1415 messageId: "sortKeys",
1416 data: {
1417 natural: "",
1418 insensitive: "",
1419 order: "desc",
1420 thisName: "À",
1421 prevName: "#"
1422 }
1423 },
1424 {
1425 messageId: "sortKeys",
1426 data: {
1427 natural: "",
1428 insensitive: "",
1429 order: "desc",
1430 thisName: "è",
1431 prevName: "Z"
1432 }
1433 }
1434 ]
1435 },
1436
1437 // desc, minKeys should error when number of keys is greater than or equal to minKeys
1438 {
1439 code: "var obj = {a:1, _:2, b:3}",
1440 options: ["desc", { minKeys: 3 }],
1441 errors: [
1442 {
1443 messageId: "sortKeys",
1444 data: {
1445 natural: "",
1446 insensitive: "",
1447 order: "desc",
1448 thisName: "b",
1449 prevName: "_"
1450 }
1451 }
1452 ]
1453 },
1454
1455 // desc, insensitive
1456 {
1457 code: "var obj = {a:1, _:2, b:3} // desc, insensitive",
1458 options: ["desc", { caseSensitive: false }],
1459 errors: [
1460 {
1461 messageId: "sortKeys",
1462 data: {
1463 natural: "",
1464 insensitive: "insensitive ",
1465 order: "desc",
1466 thisName: "b",
1467 prevName: "_"
1468 }
1469 }
1470 ]
1471 },
1472 {
1473 code: "var obj = {a:1, c:2, b:3}",
1474 options: ["desc", { caseSensitive: false }],
1475 errors: [
1476 {
1477 messageId: "sortKeys",
1478 data: {
1479 natural: "",
1480 insensitive: "insensitive ",
1481 order: "desc",
1482 thisName: "c",
1483 prevName: "a"
1484 }
1485 }
1486 ]
1487 },
1488 {
1489 code: "var obj = {b_:1, a:2, b:3}",
1490 options: ["desc", { caseSensitive: false }],
1491 errors: [
1492 {
1493 messageId: "sortKeys",
1494 data: {
1495 natural: "",
1496 insensitive: "insensitive ",
1497 order: "desc",
1498 thisName: "b",
1499 prevName: "a"
1500 }
1501 }
1502 ]
1503 },
1504 {
1505 code: "var obj = {b_:1, c:2, C:3}",
1506 options: ["desc", { caseSensitive: false }],
1507 errors: [
1508 {
1509 messageId: "sortKeys",
1510 data: {
1511 natural: "",
1512 insensitive: "insensitive ",
1513 order: "desc",
1514 thisName: "c",
1515 prevName: "b_"
1516 }
1517 }
1518 ]
1519 },
1520 {
1521 code: "var obj = {$:1, _:2, A:3, a:4}",
1522 options: ["desc", { caseSensitive: false }],
1523 errors: [
1524 {
1525 messageId: "sortKeys",
1526 data: {
1527 natural: "",
1528 insensitive: "insensitive ",
1529 order: "desc",
1530 thisName: "_",
1531 prevName: "$"
1532 }
1533 },
1534 {
1535 messageId: "sortKeys",
1536 data: {
1537 natural: "",
1538 insensitive: "insensitive ",
1539 order: "desc",
1540 thisName: "A",
1541 prevName: "_"
1542 }
1543 }
1544 ]
1545 },
1546 {
1547 code: "var obj = {1:1, 2:4, A:3, '11':2}",
1548 options: ["desc", { caseSensitive: false }],
1549 errors: [
1550 {
1551 messageId: "sortKeys",
1552 data: {
1553 natural: "",
1554 insensitive: "insensitive ",
1555 order: "desc",
1556 thisName: "2",
1557 prevName: "1"
1558 }
1559 },
1560 {
1561 messageId: "sortKeys",
1562 data: {
1563 natural: "",
1564 insensitive: "insensitive ",
1565 order: "desc",
1566 thisName: "A",
1567 prevName: "2"
1568 }
1569 }
1570 ]
1571 },
1572 {
1573 code: "var obj = {'#':1, À:3, 'Z':2, è:4}",
1574 options: ["desc", { caseSensitive: false }],
1575 errors: [
1576 {
1577 messageId: "sortKeys",
1578 data: {
1579 natural: "",
1580 insensitive: "insensitive ",
1581 order: "desc",
1582 thisName: "À",
1583 prevName: "#"
1584 }
1585 },
1586 {
1587 messageId: "sortKeys",
1588 data: {
1589 natural: "",
1590 insensitive: "insensitive ",
1591 order: "desc",
1592 thisName: "è",
1593 prevName: "Z"
1594 }
1595 }
1596 ]
1597 },
1598
1599 // desc, insensitive should error when number of keys is greater than or equal to minKeys
1600 {
1601 code: "var obj = {a:1, _:2, b:3}",
1602 options: ["desc", { caseSensitive: false, minKeys: 2 }],
1603 errors: [
1604 {
1605 messageId: "sortKeys",
1606 data: {
1607 natural: "",
1608 insensitive: "insensitive ",
1609 order: "desc",
1610 thisName: "b",
1611 prevName: "_"
1612 }
1613 }
1614 ]
1615 },
1616
1617 // desc, natural
1618 {
1619 code: "var obj = {a:1, _:2, b:3} // desc, natural",
1620 options: ["desc", { natural: true }],
1621 errors: [
1622 {
1623 messageId: "sortKeys",
1624 data: {
1625 natural: "natural ",
1626 insensitive: "",
1627 order: "desc",
1628 thisName: "b",
1629 prevName: "_"
1630 }
1631 }
1632 ]
1633 },
1634 {
1635 code: "var obj = {a:1, c:2, b:3}",
1636 options: ["desc", { natural: true }],
1637 errors: [
1638 {
1639 messageId: "sortKeys",
1640 data: {
1641 natural: "natural ",
1642 insensitive: "",
1643 order: "desc",
1644 thisName: "c",
1645 prevName: "a"
1646 }
1647 }
1648 ]
1649 },
1650 {
1651 code: "var obj = {b_:1, a:2, b:3}",
1652 options: ["desc", { natural: true }],
1653 errors: [
1654 {
1655 messageId: "sortKeys",
1656 data: {
1657 natural: "natural ",
1658 insensitive: "",
1659 order: "desc",
1660 thisName: "b",
1661 prevName: "a"
1662 }
1663 }
1664 ]
1665 },
1666 {
1667 code: "var obj = {b_:1, c:2, C:3}",
1668 options: ["desc", { natural: true }],
1669 errors: [
1670 {
1671 messageId: "sortKeys",
1672 data: {
1673 natural: "natural ",
1674 insensitive: "",
1675 order: "desc",
1676 thisName: "c",
1677 prevName: "b_"
1678 }
1679 }
1680 ]
1681 },
1682 {
1683 code: "var obj = {$:1, _:2, A:3, a:4}",
1684 options: ["desc", { natural: true }],
1685 errors: [
1686 {
1687 messageId: "sortKeys",
1688 data: {
1689 natural: "natural ",
1690 insensitive: "",
1691 order: "desc",
1692 thisName: "_",
1693 prevName: "$"
1694 }
1695 },
1696 {
1697 messageId: "sortKeys",
1698 data: {
1699 natural: "natural ",
1700 insensitive: "",
1701 order: "desc",
1702 thisName: "A",
1703 prevName: "_"
1704 }
1705 },
1706 {
1707 messageId: "sortKeys",
1708 data: {
1709 natural: "natural ",
1710 insensitive: "",
1711 order: "desc",
1712 thisName: "a",
1713 prevName: "A"
1714 }
1715 }
1716 ]
1717 },
1718 {
1719 code: "var obj = {1:1, 2:4, A:3, '11':2}",
1720 options: ["desc", { natural: true }],
1721 errors: [
1722 {
1723 messageId: "sortKeys",
1724 data: {
1725 natural: "natural ",
1726 insensitive: "",
1727 order: "desc",
1728 thisName: "2",
1729 prevName: "1"
1730 }
1731 },
1732 {
1733 messageId: "sortKeys",
1734 data: {
1735 natural: "natural ",
1736 insensitive: "",
1737 order: "desc",
1738 thisName: "A",
1739 prevName: "2"
1740 }
1741 }
1742 ]
1743 },
1744 {
1745 code: "var obj = {'#':1, À:3, 'Z':2, è:4}",
1746 options: ["desc", { natural: true }],
1747 errors: [
1748 {
1749 messageId: "sortKeys",
1750 data: {
1751 natural: "natural ",
1752 insensitive: "",
1753 order: "desc",
1754 thisName: "À",
1755 prevName: "#"
1756 }
1757 },
1758 {
1759 messageId: "sortKeys",
1760 data: {
1761 natural: "natural ",
1762 insensitive: "",
1763 order: "desc",
1764 thisName: "è",
1765 prevName: "Z"
1766 }
1767 }
1768 ]
1769 },
1770
1771 // desc, natural should error when number of keys is greater than or equal to minKeys
1772 {
1773 code: "var obj = {a:1, _:2, b:3}",
1774 options: ["desc", { natural: true, minKeys: 3 }],
1775 errors: [
1776 {
1777 messageId: "sortKeys",
1778 data: {
1779 natural: "natural ",
1780 insensitive: "",
1781 order: "desc",
1782 thisName: "b",
1783 prevName: "_"
1784 }
1785 }
1786 ]
1787 },
1788
1789 // desc, natural, insensitive
1790 {
1791 code: "var obj = {a:1, _:2, b:3} // desc, natural, insensitive",
1792 options: ["desc", { natural: true, caseSensitive: false }],
1793 errors: [
1794 {
1795 messageId: "sortKeys",
1796 data: {
1797 natural: "natural ",
1798 insensitive: "insensitive ",
1799 order: "desc",
1800 thisName: "b",
1801 prevName: "_"
1802 }
1803 }
1804 ]
1805 },
1806 {
1807 code: "var obj = {a:1, c:2, b:3}",
1808 options: ["desc", { natural: true, caseSensitive: false }],
1809 errors: [
1810 {
1811 messageId: "sortKeys",
1812 data: {
1813 natural: "natural ",
1814 insensitive: "insensitive ",
1815 order: "desc",
1816 thisName: "c",
1817 prevName: "a"
1818 }
1819 }
1820 ]
1821 },
1822 {
1823 code: "var obj = {b_:1, a:2, b:3}",
1824 options: ["desc", { natural: true, caseSensitive: false }],
1825 errors: [
1826 {
1827 messageId: "sortKeys",
1828 data: {
1829 natural: "natural ",
1830 insensitive: "insensitive ",
1831 order: "desc",
1832 thisName: "b",
1833 prevName: "a"
1834 }
1835 }
1836 ]
1837 },
1838 {
1839 code: "var obj = {b_:1, c:2, C:3}",
1840 options: ["desc", { natural: true, caseSensitive: false }],
1841 errors: [
1842 {
1843 messageId: "sortKeys",
1844 data: {
1845 natural: "natural ",
1846 insensitive: "insensitive ",
1847 order: "desc",
1848 thisName: "c",
1849 prevName: "b_"
1850 }
1851 }
1852 ]
1853 },
1854 {
1855 code: "var obj = {$:1, _:2, A:3, a:4}",
1856 options: ["desc", { natural: true, caseSensitive: false }],
1857 errors: [
1858 {
1859 messageId: "sortKeys",
1860 data: {
1861 natural: "natural ",
1862 insensitive: "insensitive ",
1863 order: "desc",
1864 thisName: "_",
1865 prevName: "$"
1866 }
1867 },
1868 {
1869 messageId: "sortKeys",
1870 data: {
1871 natural: "natural ",
1872 insensitive: "insensitive ",
1873 order: "desc",
1874 thisName: "A",
1875 prevName: "_"
1876 }
1877 }
1878 ]
1879 },
1880 {
1881 code: "var obj = {1:1, 2:4, '11':2, A:3}",
1882 options: ["desc", { natural: true, caseSensitive: false }],
1883 errors: [
1884 {
1885 messageId: "sortKeys",
1886 data: {
1887 natural: "natural ",
1888 insensitive: "insensitive ",
1889 order: "desc",
1890 thisName: "2",
1891 prevName: "1"
1892 }
1893 },
1894 {
1895 messageId: "sortKeys",
1896 data: {
1897 natural: "natural ",
1898 insensitive: "insensitive ",
1899 order: "desc",
1900 thisName: "11",
1901 prevName: "2"
1902 }
1903 },
1904 {
1905 messageId: "sortKeys",
1906 data: {
1907 natural: "natural ",
1908 insensitive: "insensitive ",
1909 order: "desc",
1910 thisName: "A",
1911 prevName: "11"
1912 }
1913 }
1914 ]
1915 },
1916 {
1917 code: "var obj = {'#':1, À:3, 'Z':2, è:4}",
1918 options: ["desc", { natural: true, caseSensitive: false }],
1919 errors: [
1920 {
1921 messageId: "sortKeys",
1922 data: {
1923 natural: "natural ",
1924 insensitive: "insensitive ",
1925 order: "desc",
1926 thisName: "À",
1927 prevName: "#"
1928 }
1929 },
1930 {
1931 messageId: "sortKeys",
1932 data: {
1933 natural: "natural ",
1934 insensitive: "insensitive ",
1935 order: "desc",
1936 thisName: "è",
1937 prevName: "Z"
1938 }
1939 }
1940 ]
1941 },
1942
1943 // desc, natural, insensitive should error when number of keys is greater than or equal to minKeys
1944 {
1945 code: "var obj = {a:1, _:2, b:3}",
1946 options: ["desc", { natural: true, caseSensitive: false, minKeys: 2 }],
1947 errors: [
1948 {
1949 messageId: "sortKeys",
1950 data: {
1951 natural: "natural ",
1952 insensitive: "insensitive ",
1953 order: "desc",
1954 thisName: "b",
1955 prevName: "_"
1956 }
1957 }
1958 ]
1959 },
1960
1961 // When allowLineSeparatedGroups option is false
1962 {
1963 code: `
1964 var obj = {
1965 b: 1,
1966 c: 2,
1967 a: 3
1968 }
1969 `,
1970 options: ["asc", { allowLineSeparatedGroups: false }],
1971 errors: [
1972 {
1973 messageId: "sortKeys",
1974 data: {
1975 natural: "",
1976 insensitive: "",
1977 order: "asc",
1978 thisName: "a",
1979 prevName: "c"
1980 }
1981 }
1982 ]
1983 },
1984 {
1985 code: `
1986 let obj = {
1987 b
1988
1989 ,a
1990 }
1991 `,
1992 options: ["asc", { allowLineSeparatedGroups: false }],
1993 parserOptions: { ecmaVersion: 6 },
1994 errors: [
1995 {
1996 messageId: "sortKeys",
1997 data: {
1998 natural: "",
1999 insensitive: "",
2000 order: "asc",
2001 thisName: "a",
2002 prevName: "b"
2003 }
2004 }
2005 ]
2006 },
2007
2008 // When allowLineSeparatedGroups option is true
2009 {
2010 code: `
2011 var obj = {
2012 b: 1,
2013 c () {
2014
2015 },
2016 a: 3
2017 }
2018 `,
2019 options: ["asc", { allowLineSeparatedGroups: true }],
2020 parserOptions: { ecmaVersion: 6 },
2021 errors: [
2022 {
2023 messageId: "sortKeys",
2024 data: {
2025 natural: "",
2026 insensitive: "",
2027 order: "asc",
2028 thisName: "a",
2029 prevName: "c"
2030 }
2031 }
2032 ]
2033 },
2034 {
2035 code: `
2036 var obj = {
2037 a: 1,
2038 b: 2,
2039
2040 z () {
2041
2042 },
2043 y: 3
2044 }
2045 `,
2046 options: ["asc", { allowLineSeparatedGroups: true }],
2047 parserOptions: { ecmaVersion: 6 },
2048 errors: [
2049 {
2050 messageId: "sortKeys",
2051 data: {
2052 natural: "",
2053 insensitive: "",
2054 order: "asc",
2055 thisName: "y",
2056 prevName: "z"
2057 }
2058 }
2059 ]
2060 },
2061 {
2062 code: `
2063 var obj = {
2064 b: 1,
2065 c () {
2066 },
2067 // comment
2068 a: 3
2069 }
2070 `,
2071 options: ["asc", { allowLineSeparatedGroups: true }],
2072 parserOptions: { ecmaVersion: 6 },
2073 errors: [
2074 {
2075 messageId: "sortKeys",
2076 data: {
2077 natural: "",
2078 insensitive: "",
2079 order: "asc",
2080 thisName: "a",
2081 prevName: "c"
2082 }
2083 }
2084 ]
2085 },
2086 {
2087 code: `
2088 var obj = {
2089 b,
2090 [a+b]: 1,
2091 a // sort-keys: 'a' should be before 'b'
2092 }
2093 `,
2094 options: ["asc", { allowLineSeparatedGroups: true }],
2095 parserOptions: { ecmaVersion: 6 },
2096 errors: [
2097 {
2098 messageId: "sortKeys",
2099 data: {
2100 natural: "",
2101 insensitive: "",
2102 order: "asc",
2103 thisName: "a",
2104 prevName: "b"
2105 }
2106 }
2107 ]
2108 },
2109 {
2110 code: `
2111 var obj = {
2112 c: 1,
2113 d: 2,
2114 // comment
2115 // comment
2116 b() {
2117 },
2118 e: 4
2119 }
2120 `,
2121 options: ["asc", { allowLineSeparatedGroups: true }],
2122 parserOptions: { ecmaVersion: 6 },
2123 errors: [
2124 {
2125 messageId: "sortKeys",
2126 data: {
2127 natural: "",
2128 insensitive: "",
2129 order: "asc",
2130 thisName: "b",
2131 prevName: "d"
2132 }
2133 }
2134 ]
2135 },
2136 {
2137 code: `
2138 var obj = {
2139 c: 1,
2140 d: 2,
2141
2142 z() {
2143
2144 },
2145 f: 3,
2146 /*
2147
2148
2149 */
2150 [a+b]: 1,
2151 b: 1,
2152 e: 2
2153 }
2154 `,
2155 options: ["asc", { allowLineSeparatedGroups: true }],
2156 parserOptions: { ecmaVersion: 6 },
2157 errors: [
2158 {
2159 messageId: "sortKeys",
2160 data: {
2161 natural: "",
2162 insensitive: "",
2163 order: "asc",
2164 thisName: "f",
2165 prevName: "z"
2166 }
2167 },
2168 {
2169 messageId: "sortKeys",
2170 data: {
2171 natural: "",
2172 insensitive: "",
2173 order: "asc",
2174 thisName: "b",
2175 prevName: "f"
2176 }
2177 }
2178 ]
2179 },
2180 {
2181 code: `
2182 var obj = {
2183 b: "/*",
2184 a: "*/",
2185 }
2186 `,
2187 options: ["asc", { allowLineSeparatedGroups: true }],
2188 errors: [
2189 {
2190 messageId: "sortKeys",
2191 data: {
2192 natural: "",
2193 insensitive: "",
2194 order: "asc",
2195 thisName: "a",
2196 prevName: "b"
2197 }
2198 }
2199 ]
2200 },
2201 {
2202 code: `
2203 var obj = {
2204 b: 1
2205 // comment before comma
2206 , a: 2
2207 };
2208 `,
2209 options: ["asc", { allowLineSeparatedGroups: true }],
2210 parserOptions: { ecmaVersion: 6 },
2211 errors: [
2212 {
2213 messageId: "sortKeys",
2214 data: {
2215 natural: "",
2216 insensitive: "",
2217 order: "asc",
2218 thisName: "a",
2219 prevName: "b"
2220 }
2221 }
2222 ]
2223 },
2224 {
2225 code: `
2226 let obj = {
2227 b,
2228 [foo()]: [
2229 // ↓ this blank is inside a property and therefore should not count
2230
2231 ],
2232 a
2233 }
2234 `,
2235 options: ["asc", { allowLineSeparatedGroups: true }],
2236 parserOptions: { ecmaVersion: 2018 },
2237 errors: [
2238 {
2239 messageId: "sortKeys",
2240 data: {
2241 natural: "",
2242 insensitive: "",
2243 order: "asc",
2244 thisName: "a",
2245 prevName: "b"
2246 }
2247 }
2248 ]
2249 }
2250 ]
2251 });