Skip to content

Commit

Permalink
fix(eslint-plugin): fix autofixer for computed properties (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed Mar 3, 2020
1 parent 608a750 commit ba22ea7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -403,7 +403,7 @@ export default createRule<Options, MessageId>({
function checkOptionalMemberExpression(
node: TSESTree.OptionalMemberExpression,
): void {
checkOptionalChain(node, node.object, '.');
checkOptionalChain(node, node.object, node.computed ? '' : '.');
}

function checkOptionalCallExpression(
Expand Down
Expand Up @@ -222,6 +222,7 @@ anyValue?.();
let unknownValue: unknown;
unknownValue?.();
`,
'const foo = [1, 2, 3][0];',
],
invalid: [
// Ensure that it's checking in all the right places
Expand Down Expand Up @@ -575,5 +576,18 @@ foo
},
],
},
{
code: 'const foo = [1, 2, 3]?.[0];',
output: 'const foo = [1, 2, 3][0];',
errors: [
{
messageId: 'neverOptionalChain',
line: 1,
endLine: 1,
column: 22,
endColumn: 24,
},
],
},
],
});

0 comments on commit ba22ea7

Please sign in to comment.