fix(prefer-optional-chain): false positive on unrelated comparisons#778
Conversation
How to use the Graphite Merge QueueAdd the label 0-merge to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a false positive in the prefer-optional-chain rule where unrelated && comparisons could be incorrectly grouped into an optional-chaining candidate chain (reported in #20147).
Changes:
- Add a regression test covering
&&with unrelated non-nullish comparisons (no optional-chain suggestion expected). - Update AND-chain construction to treat non-nullish comparisons as “chain terminators” and to avoid starting a chain on them.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/rules/prefer_optional_chain/prefer_optional_chain_test.go | Adds a valid-case regression test reproducing issue #20147. |
| internal/rules/prefer_optional_chain/prefer_optional_chain.go | Adjusts AND-chain building logic to avoid chaining through unrelated non-nullish comparisons. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Merge activity
|
2e60e01 to
9bd6422
Compare

fixes oxc-project/oxc#20147