-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): [prefer-optional-chain] ignore check
option for most RHS of a chain
#11272
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
base: main
Are you sure you want to change the base?
fix(eslint-plugin): [prefer-optional-chain] ignore check
option for most RHS of a chain
#11272
Conversation
Thanks for the PR, @nayounsang! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
❌ Deploy Preview for typescript-eslint failed.
|
View your CI Pipeline Execution ↗ for commit 6fafc22
☁️ Nx Cloud last updated this comment at |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #11272 +/- ##
=======================================
Coverage 90.86% 90.86%
=======================================
Files 503 503
Lines 51036 51030 -6
Branches 8424 8416 -8
=======================================
- Hits 46373 46368 -5
Misses 4648 4648
+ Partials 15 14 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
?.()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally looks great! Just one big question on the implementation approach we want to take. Looking forward to hearing your thoughts!
packages/eslint-plugin/src/rules/prefer-optional-chain-utils/gatherLogicalOperands.ts
Outdated
Show resolved
Hide resolved
…ypescript-eslint into void-optional-chain
This PR has the effect that the following code is flagged (with declare const maybeVoid: void | { x: () => { some: 'object' } };
maybeVoid && maybeVoid.x(); I'm not sure that that's what we want? I'd say instead the goal is that a In other words, as far as implementation - we're not looking to include possibly- WDYT? |
I've realized — I think this is a much more general bug. The declare const x: { a: string };
// checkString: true
const y = x && x.a; // correctly reports
// checkString: false
const y = x && x.a; // (BUG) doesn't report So, if we generally fix the logic so that the type checking only applies to the LHS of a potential chain expression |
Then, I guess we can check it except for right most. I will finish the work on void and reply. |
After thinking about it further with comments and usage examples, I think the checkVoid option is not necessary. checkXXX is useful when there is an accessible method. When considering real-world usage, I couldn't think of a case where checkXXX would be used for void. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is moving in the right direction, but the current state of the PR seems to be mostly extraneous changes. Let's clean it up to be focused on the changes related to the bug. Thanks!
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/prefer-optional-chain-utils/gatherLogicalOperands.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(see review)
Oh, sorry. I misunderstood your review. Now I know what to do |
?.()
check
option for most RHS of a chain
Hey @nayounsang — is this ready for another review pass? If so, we ask that you request review in the GUI so we know to take another look. If not, take your time and don't mind me! Just looked like it might be ready for another pass. Thanks! |
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Outdated
Show resolved
Hide resolved
…r-optional-chain.test.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
PR Checklist
?.()
#11270Overview