@@ -24,6 +24,15 @@ ruleTester.run("no-useless-computed-key", rule, {
2424 "({ [x]: 0 });" ,
2525 "({ a: 0, [b](){} })" ,
2626 "({ ['__proto__']: [] })" ,
27+ "var { 'a': foo } = obj" ,
28+ "var { [a]: b } = obj;" ,
29+ "var { a } = obj;" ,
30+ "var { a: a } = obj;" ,
31+ "var { a: b } = obj;" ,
32+
33+ // ['__proto__'] is useless computed key in object patterns, but the rule doesn't report it for backwards compatibility since it's frozen
34+ "var { ['__proto__']: a } = obj" ,
35+
2736 { code : "class Foo { a() {} }" , options : [ { enforceForClassMembers : true } ] } ,
2837 { code : "class Foo { 'a'() {} }" , options : [ { enforceForClassMembers : true } ] } ,
2938 { code : "class Foo { [x]() {} }" , options : [ { enforceForClassMembers : true } ] } ,
@@ -64,6 +73,14 @@ ruleTester.run("no-useless-computed-key", rule, {
6473 data : { property : "'0'" } ,
6574 type : "Property"
6675 } ]
76+ } , {
77+ code : "var { ['0']: a } = obj" ,
78+ output : "var { '0': a } = obj" ,
79+ errors : [ {
80+ messageId : "unnecessarilyComputedProperty" ,
81+ data : { property : "'0'" } ,
82+ type : "Property"
83+ } ]
6784 } , {
6885 code : "({ ['0+1,234']: 0 })" ,
6986 output : "({ '0+1,234': 0 })" ,
@@ -80,6 +97,14 @@ ruleTester.run("no-useless-computed-key", rule, {
8097 data : { property : "0" } ,
8198 type : "Property"
8299 } ]
100+ } , {
101+ code : "var { [0]: a } = obj" ,
102+ output : "var { 0: a } = obj" ,
103+ errors : [ {
104+ messageId : "unnecessarilyComputedProperty" ,
105+ data : { property : "0" } ,
106+ type : "Property"
107+ } ]
83108 } , {
84109 code : "({ ['x']: 0 })" ,
85110 output : "({ 'x': 0 })" ,
@@ -88,6 +113,14 @@ ruleTester.run("no-useless-computed-key", rule, {
88113 data : { property : "'x'" } ,
89114 type : "Property"
90115 } ]
116+ } , {
117+ code : "var { ['x']: a } = obj" ,
118+ output : "var { 'x': a } = obj" ,
119+ errors : [ {
120+ messageId : "unnecessarilyComputedProperty" ,
121+ data : { property : "'x'" } ,
122+ type : "Property"
123+ } ]
91124 } , {
92125 code : "({ ['x']() {} })" ,
93126 output : "({ 'x'() {} })" ,
@@ -120,6 +153,14 @@ ruleTester.run("no-useless-computed-key", rule, {
120153 data : { property : "'x'" } ,
121154 type : "Property"
122155 } ]
156+ } , {
157+ code : "var { [('x')]: a } = obj" ,
158+ output : "var { 'x': a } = obj" ,
159+ errors : [ {
160+ messageId : "unnecessarilyComputedProperty" ,
161+ data : { property : "'x'" } ,
162+ type : "Property"
163+ } ]
123164 } , {
124165 code : "({ *['x']() {} })" ,
125166 output : "({ *'x'() {} })" ,
0 commit comments