fix(eslint-plugin): [prefer-optional-chain] suggests optional chaining during strict null equality check#8717
Conversation
|
Thanks for the PR, @jsfm01! 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 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
ceab321 to
6fb2f03
Compare
JoshuaKGoldberg
left a comment
There was a problem hiding this comment.
LGTM, thanks! 🎉
Leaving open for a bit since these nullability rules can get tricky. See also: #8559.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8717 +/- ##
==========================================
- Coverage 87.38% 87.37% -0.02%
==========================================
Files 259 255 -4
Lines 12581 12503 -78
Branches 3930 3925 -5
==========================================
- Hits 10994 10924 -70
+ Misses 1313 1304 -9
- Partials 274 275 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|

PR Checklist
Overview
The rule suggests replacing logical AND operators (&&) with optional chaining (?.) for checking both object reference and property existence.
However, this substitution can unintentionally alter code logic, especially when separate checks for object existence and property values are needed.
The solution provided skips cases involving strict null equality for these particular cases preventing unintended changes to code logic.