Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: [prefer-optional-chain] Suggest optional chain when the start of the expression is already optionally chained #5697

Closed
4 tasks done
omril1 opened this issue Sep 29, 2022 · 2 comments · Fixed by #6397
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@omril1
Copy link
Contributor

omril1 commented Sep 29, 2022

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/prefer-optional-chain/

Description

I propose that the prefer-optional-chain should suggest combining logical expressions that start with an optional chain

Discovered while making test cases in #5594

Fail

foo?.bar && foo.bar?.() && foo.bar?.().baz

Pass

foo?.bar?.()?.baz

Additional Info

No response

@omril1 omril1 added enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Sep 29, 2022
@bradzacher
Copy link
Member

Yeah the only issue I've found is that it really is suuuper complicated to write all the logic to make this work.

It looks so easy on paper, but comparing two asts and understanding how they relate in the general case to determine the appropriate fix is just really difficult to do.

@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Sep 29, 2022
@Josh-Cena
Copy link
Member

Fixed by #6397

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants