diff --git a/tests/lib/rules/computed-property-spacing.js b/tests/lib/rules/computed-property-spacing.js index eff0c0a73bd..35533d9e686 100644 --- a/tests/lib/rules/computed-property-spacing.js +++ b/tests/lib/rules/computed-property-spacing.js @@ -265,7 +265,30 @@ ruleTester.run("computed-property-spacing", rule, { ].join("\n"), options: ["never"], parserOptions: { ecmaVersion: 6 } + }, + + // Destructuring Assignment + { + code: "const { [a]: someProp } = obj;", + options: ["never"], + parserOptions: { ecmaVersion: 6 } + }, + { + code: "({ [a]: someProp } = obj);", + options: ["never"], + parserOptions: { ecmaVersion: 6 } + }, + { + code: "const { [ a ]: someProp } = obj;", + options: ["always"], + parserOptions: { ecmaVersion: 6 } + }, + { + code: "({ [ a ]: someProp } = obj);", + options: ["always"], + parserOptions: { ecmaVersion: 6 } } + ], invalid: [ @@ -2062,6 +2085,66 @@ ruleTester.run("computed-property-spacing", rule, { { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } ] + }, + + // Destructuring Assignment + { + code: "const { [ a]: someProp } = obj;", + output: "const { [a]: someProp } = obj;", + options: ["never"], + parserOptions: { ecmaVersion: 2022 }, + errors: [ + { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } } + ] + }, + { + code: "const { [a ]: someProp } = obj;", + output: "const { [a]: someProp } = obj;", + options: ["never"], + parserOptions: { ecmaVersion: 2022 }, + errors: [ + { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } + ] + }, + { + code: "const { [ a ]: someProp } = obj;", + output: "const { [a]: someProp } = obj;", + options: ["never"], + parserOptions: { ecmaVersion: 2022 }, + errors: [ + { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, + { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } + ] + }, + { + code: "({ [ a ]: someProp } = obj);", + output: "({ [a]: someProp } = obj);", + options: ["never"], + parserOptions: { ecmaVersion: 2022 }, + errors: [ + { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, + { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } + ] + }, + { + code: "const { [a]: someProp } = obj;", + output: "const { [ a ]: someProp } = obj;", + options: ["always"], + parserOptions: { ecmaVersion: 2022 }, + errors: [ + { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, + { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } + ] + }, + { + code: "({ [a]: someProp } = obj);", + output: "({ [ a ]: someProp } = obj);", + options: ["always"], + parserOptions: { ecmaVersion: 2022 }, + errors: [ + { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, + { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } + ] } ] });