Skip to content

fix(prefer-optional-chain): false positive on unrelated comparisons#778

Merged
graphite-app[bot] merged 1 commit intomainfrom
c/03-09-fix_prefer-optional-chain_false_positive_on_unrelated_comparisons
Mar 9, 2026
Merged

fix(prefer-optional-chain): false positive on unrelated comparisons#778
graphite-app[bot] merged 1 commit intomainfrom
c/03-09-fix_prefer-optional-chain_false_positive_on_unrelated_comparisons

Conversation

@camc314
Copy link
Copy Markdown
Contributor

@camc314 camc314 commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

camc314 commented Mar 9, 2026


How to use the Graphite Merge Queue

Add 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.

@camc314 camc314 marked this pull request as ready for review March 9, 2026 17:32
Copilot AI review requested due to automatic review settings March 9, 2026 17:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@camc314 camc314 changed the title fix prefer-optional-chain false positive on unrelated comparisons fix(prefer-optional-chain): false positive on unrelated comparisons Mar 9, 2026
@camc314 camc314 self-assigned this Mar 9, 2026
@camc314 camc314 added the 0-merge label Mar 9, 2026
Copy link
Copy Markdown
Contributor Author

camc314 commented Mar 9, 2026

Merge activity

@graphite-app graphite-app Bot force-pushed the c/03-09-fix_prefer-optional-chain_false_positive_on_unrelated_comparisons branch from 2e60e01 to 9bd6422 Compare March 9, 2026 18:05
@graphite-app graphite-app Bot merged commit 9bd6422 into main Mar 9, 2026
8 checks passed
@graphite-app graphite-app Bot deleted the c/03-09-fix_prefer-optional-chain_false_positive_on_unrelated_comparisons branch March 9, 2026 18:12
@graphite-app graphite-app Bot removed the 0-merge label Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: prefer-optional-chain false positive on unrelated && conditions comparing different objects

2 participants