Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(eslint-plugin): [prefer-optional-chain] handle binary expressions…
… in negated or (#5992)

* fix/issue5991-fix-prefer-optional-chain-BinaryExpression-in-negated-or

* CR
  • Loading branch information
omril1 committed Nov 16, 2022
1 parent 0fb44ba commit 2778ff0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/prefer-optional-chain.ts
Expand Up @@ -400,6 +400,7 @@ export default util.createRule({

case AST_NODE_TYPES.Literal:
case AST_NODE_TYPES.TemplateLiteral:
case AST_NODE_TYPES.BinaryExpression:
propertyText = sourceCode.getText(node.property);
break;

Expand Down
Expand Up @@ -198,6 +198,8 @@ ruleTester.run('prefer-optional-chain', rule, {
'foo && foo[bar as string] && foo[bar as string].baz;',
'foo && foo[1 + 2] && foo[1 + 2].baz;',
'foo && foo[typeof bar] && foo[typeof bar].baz;',
'!foo[1 + 1] || !foo[1 + 2];',
'!foo[1 + 1] || !foo[1 + 1].foo;',
'!foo || !foo[bar as string] || !foo[bar as string].baz;',
'!foo || !foo[1 + 2] || !foo[1 + 2].baz;',
'!foo || !foo[typeof bar] || !foo[typeof bar].baz;',
Expand Down

0 comments on commit 2778ff0

Please sign in to comment.