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 !foo || !foo.bar as a valid match for the rule #5245

Closed
4 tasks done
omril1 opened this issue Jun 25, 2022 · 2 comments · Fixed by #5266 or #5594
Closed
4 tasks done
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 Jun 25, 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 rule should also check for !foo || !foo.bar the boolean alternative form of !(foo && foo.bar) to be suggested as !foo?.bar

Fail

!foo || !foo.bar;

!foo || !foo[bar];

!foo || !foo.bar || !foo.bar.baz || !foo.bar.baz();

Pass

!foo?.bar;

!foo?.[bar];

!foo?.bar?.baz?.();

Additional Info

Willing to open a PR

@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 Jun 25, 2022
@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 Jun 26, 2022
@bradzacher bradzacher reopened this Aug 29, 2022
@bradzacher
Copy link
Member

bradzacher commented Aug 29, 2022

Just a heads up @omril1 - #5266 introduced some crashes for users, so we reverted the PR.
Generally we would look to fix forward, but because the bugs were discovered by users in the release week, we thought it best to revert it to fix for the upcoming release, and we can look to rebuild the PR without the bugs without a time pressure.

@omril1
Copy link
Contributor Author

omril1 commented Aug 29, 2022

@bradzacher Thanks, I'm taking a look

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
2 participants