@@ -278,7 +278,9 @@ ruleTester.run("key-spacing", rule, {
278278 " method() {" ,
279279 " return 42;" ,
280280 " }," ,
281- " baz: 456" ,
281+ " baz: 456," ,
282+ " 10: " ,
283+ " 10" ,
282284 "};"
283285 ] . join ( "\n" ) ,
284286 options : [ { align : "value" } ] ,
@@ -360,6 +362,10 @@ ruleTester.run("key-spacing", rule, {
360362 " bat: function() {" ,
361363 " return this.a;" ,
362364 " }," ,
365+ " barfoo:" ,
366+ " [" ,
367+ " 1" ,
368+ " ]," ,
363369 " baz: 42" ,
364370 "};"
365371 ] . join ( "\n" ) ,
@@ -633,6 +639,10 @@ ruleTester.run("key-spacing", rule, {
633639 " internalGroup: {" ,
634640 " internal : true," ,
635641 " ext : false" ,
642+ " }," ,
643+ " func3:" ,
644+ " function () {" ,
645+ " var test3 = true;" ,
636646 " }" ,
637647 "})"
638648 ] . join ( "\n" ) ,
@@ -971,6 +981,80 @@ ruleTester.run("key-spacing", rule, {
971981 }
972982 } ] ,
973983 parserOptions : { ecmaVersion : 6 }
984+ } ,
985+
986+ // https://github.com/eslint/eslint/issues/16490
987+ {
988+ code : `
989+ var foo =
990+ {
991+ id: 1,
992+ code: 2,
993+ [n]: 3,
994+ message:
995+ "some value on the next line",
996+ };
997+ ` ,
998+ options : [ {
999+ align : "value"
1000+ } ] ,
1001+ parserOptions : { ecmaVersion : 6 }
1002+ } ,
1003+ {
1004+ code : `
1005+ var foo =
1006+ {
1007+ id : 1,
1008+ code : 2,
1009+ message :
1010+ "some value on the next line",
1011+ };
1012+ ` ,
1013+ options : [ {
1014+ align : "colon" ,
1015+ beforeColon : true
1016+ } ]
1017+ } ,
1018+ {
1019+ code : `
1020+ ({
1021+ a: 1,
1022+ // different group
1023+ bcd:
1024+ 2
1025+ })
1026+ ` ,
1027+ options : [ {
1028+ align : "value"
1029+ } ]
1030+ } ,
1031+ {
1032+ code : `
1033+ ({
1034+ foo : 1,
1035+ bar : 2,
1036+ foobar :
1037+ 3
1038+ })
1039+ ` ,
1040+ options : [ {
1041+ align : "value" ,
1042+ beforeColon : true ,
1043+ mode : "minimum"
1044+ } ]
1045+ } ,
1046+ {
1047+ code : `
1048+ ({
1049+ oneLine: 1,
1050+ ["some key " +
1051+ "spanning multiple lines"]: 2
1052+ })
1053+ ` ,
1054+ options : [ {
1055+ align : "value"
1056+ } ] ,
1057+ parserOptions : { ecmaVersion : 6 }
9741058 } ] ,
9751059 invalid : [ {
9761060 code : "var a ={'key' : value };" ,
@@ -1464,7 +1548,9 @@ ruleTester.run("key-spacing", rule, {
14641548 " method() {" ,
14651549 " return 42;" ,
14661550 " }," ,
1467- " baz: 456" ,
1551+ " baz: 456," ,
1552+ " 10: " ,
1553+ " 10" ,
14681554 "};"
14691555 ] . join ( "\n" ) ,
14701556 output : [
@@ -1473,7 +1559,9 @@ ruleTester.run("key-spacing", rule, {
14731559 " method() {" ,
14741560 " return 42;" ,
14751561 " }," ,
1476- " baz: 456" ,
1562+ " baz: 456," ,
1563+ " 10: " ,
1564+ " 10" ,
14771565 "};"
14781566 ] . join ( "\n" ) ,
14791567 options : [ { align : "value" } ] ,
@@ -2374,6 +2462,123 @@ ruleTester.run("key-spacing", rule, {
23742462 { messageId : "extraValue" , data : { computed : "" , key : "🎁" } , line : 4 , column : 21 , type : "Literal" } ,
23752463 { messageId : "extraValue" , data : { computed : "" , key : "🇮🇳" } , line : 5 , column : 23 , type : "Literal" }
23762464 ]
2377- }
2378- ]
2465+ } ,
2466+
2467+ // https://github.com/eslint/eslint/issues/16490
2468+ {
2469+ code : `
2470+ var foo =
2471+ {
2472+ id: 1,
2473+ code: 2,
2474+ [n]: 3,
2475+ message:
2476+ "some value on the next line",
2477+ };
2478+ ` ,
2479+ output : `
2480+ var foo =
2481+ {
2482+ id: 1,
2483+ code: 2,
2484+ [n]: 3,
2485+ message:
2486+ "some value on the next line",
2487+ };
2488+ ` ,
2489+ options : [ {
2490+ align : "value"
2491+ } ] ,
2492+ parserOptions : { ecmaVersion : 6 } ,
2493+ errors : [
2494+ { messageId : "extraValue" , data : { computed : "" , key : "id" } , line : 4 , column : 19 , type : "Literal" } ,
2495+ { messageId : "extraValue" , data : { computed : "" , key : "code" } , line : 5 , column : 21 , type : "Literal" } ,
2496+ { messageId : "extraValue" , data : { computed : "computed " , key : "n" } , line : 6 , column : 20 , type : "Literal" }
2497+ ]
2498+ } ,
2499+ {
2500+ code : `
2501+ var foo =
2502+ {
2503+ id : 1,
2504+ code : 2,
2505+ message :
2506+ "some value on the next line",
2507+ };
2508+ ` ,
2509+ output : `
2510+ var foo =
2511+ {
2512+ id : 1,
2513+ code : 2,
2514+ message :
2515+ "some value on the next line",
2516+ };
2517+ ` ,
2518+ options : [ {
2519+ align : "colon" ,
2520+ beforeColon : true
2521+ } ] ,
2522+ errors : [
2523+ { messageId : "extraKey" , data : { computed : "" , key : "id" } , line : 4 , column : 19 , type : "Identifier" } ,
2524+ { messageId : "extraKey" , data : { computed : "" , key : "code" } , line : 5 , column : 21 , type : "Identifier" }
2525+ ]
2526+ } ,
2527+ {
2528+ code : `
2529+ ({
2530+ a: 1,
2531+ // different group
2532+ bcd:
2533+ 2
2534+ })
2535+ ` ,
2536+ output : `
2537+ ({
2538+ a: 1,
2539+ // different group
2540+ bcd:
2541+ 2
2542+ })
2543+ ` ,
2544+ options : [ {
2545+ align : "value"
2546+ } ] ,
2547+ errors : [
2548+ { messageId : "extraValue" , data : { computed : "" , key : "a" } , line : 3 , column : 18 , type : "Literal" }
2549+ ]
2550+ } ,
2551+ {
2552+ code : [
2553+ "({" ,
2554+ " singleLine : 10," ,
2555+ " newGroup :" ,
2556+ " function() {" ,
2557+ " var test3 = true;" ,
2558+ " }" ,
2559+ "})"
2560+ ] . join ( "\n" ) ,
2561+ output : [
2562+ "({" ,
2563+ " singleLine: 10," ,
2564+ " newGroup:" ,
2565+ " function() {" ,
2566+ " var test3 = true;" ,
2567+ " }" ,
2568+ "})"
2569+ ] . join ( "\n" ) ,
2570+ options : [ {
2571+ multiLine : {
2572+ beforeColon : false
2573+ } ,
2574+ align : {
2575+ on : "colon" ,
2576+ beforeColon : true
2577+ }
2578+ } ] ,
2579+ errors : [
2580+ { messageId : "extraKey" , data : { computed : "" , key : "singleLine" } , line : 2 , column : 15 , type : "Identifier" } ,
2581+ { messageId : "extraKey" , data : { computed : "" , key : "newGroup" } , line : 3 , column : 13 , type : "Identifier" }
2582+ ]
2583+ } ]
23792584} ) ;
0 commit comments