-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: [prefer-optional-chain
] handle cases where the first logical(s) are unrelated to the proceeding logicals
#6332
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
Comments
The rule does catch the logical OR case, the issue is that the rule does not catch cases with unrelated logicals at the beginning (playground). Why? Because it's just a really, really, really hard problem to solve using the AST.
For a human this is really easy to parse and understand, but the AST this produces is this:
It's difficult to properly associate the fact that It's just a hard problem to solve in the general case! Happy to accept a PR if anyone wants to solve this in the general case! |
prefer-optional-chain
should catch logical OR caseprefer-optional-chain
] handle cases where the first logical(s) are unrelated to the proceeding logicals
Hey @bradzacher! Many thanks for the detailed answer!
to be honest is not! and can be solved easily with I remember 1 year ago I wrote a rule Code
Error 1/1
Output
update:also while checking AST Node you would use |
It's funny cos when I was writing my comment I was thinking that the entire rule could probably be refactored to do exactly that - collect the expressions to remove the AST from the equation. Theres probably a lot of abstractions that could be built into the rule to improve it and reduce the verbosity of the code. It's grown a lot over time. Again - happy to accept a PR! |
Fixed by #6397 |
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Link to the rule's documentation
https://typescript-eslint.io/rules/prefer-optional-chain
Description
here is totally safe to refactor as I mention in
Pass
Fail
Pass
Additional Info
https://typescript-eslint.io/play/#ts=4.9.3&sourceType=module&code=JYMwBAFAhARghgLzAH2WKID2mVo9gOngCcBKMAbwCgwwqBfIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WloHsalfkwCG8WmQAWo5uki9o-aJHBgAviHVA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA
The text was updated successfully, but these errors were encountered: