diff --git a/tests/lib/rules/computed-property-spacing.js b/tests/lib/rules/computed-property-spacing.js index b0ecef6eb810..a1e5834243ee 100644 --- a/tests/lib/rules/computed-property-spacing.js +++ b/tests/lib/rules/computed-property-spacing.js @@ -1906,6 +1906,28 @@ ruleTester.run("computed-property-spacing", rule, { endColumn: 19 } ] + }, + + // Optional chaining + { + code: "obj?.[1];", + output: "obj?.[ 1 ];", + options: ["always"], + parserOptions: { ecmaVersion: 2020 }, + errors: [ + { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, + { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } + ] + }, + { + code: "obj?.[ 1 ];", + output: "obj?.[1];", + options: ["never"], + parserOptions: { ecmaVersion: 2020 }, + errors: [ + { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, + { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } + ] } ] });