refactor(no-unnecessary-condition): more closely align rule implementation with upstream#809
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 refactors the no-unnecessary-condition rule implementation to more closely match upstream behavior, and updates the test suite/snapshots accordingly to reflect the new diagnostics and edge-case handling (notably around loop conditions and indexed access/nullish checks).
Changes:
- Refactors condition-checking logic (truthy/falsy, nullish-coalescing, logical expressions, predicates) and adds helper normalization for
allowConstantLoopConditions. - Adjusts valid/invalid test cases (including moving several “OXC specific” regressions) and updates snapshot expectations.
- Adds additional loop-condition coverage for
AllowConstantLoopConditions: "only-allowed-literals".
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/rules/no_unnecessary_condition/no_unnecessary_condition.go | Major refactor of condition/nullish/logical handling and loop-condition option parsing/behavior. |
| internal/rules/no_unnecessary_condition/no_unnecessary_condition_test.go | Reorganizes/updates test cases to match refactor and adds new loop-condition cases. |
| internal/rule_tester/snapshots/no-unnecessary-condition.snap | Updates expected diagnostics/ranges to match new behavior. |
💡 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.
a3a8d16 to
fdbec03
Compare
There was a problem hiding this comment.
Pull request overview
Refactors the no-unnecessary-condition rule implementation to more closely match upstream @typescript-eslint/no-unnecessary-condition, and updates the test suite/snapshots to reflect the updated behavior.
Changes:
- Reworks condition checking logic (logical expressions, loop conditions, optional chaining, and type-predicate calls) to align with upstream behavior.
- Normalizes
allowConstantLoopConditionsparsing via a dedicated helper and adjusts loop-condition test expectations. - Reorganizes/extends rule test cases and updates the snapshot output accordingly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/rules/no_unnecessary_condition/no_unnecessary_condition.go | Refactors rule logic: loop-condition handling, boolean/logical checks, optional chaining, and type predicate call analysis. |
| internal/rules/no_unnecessary_condition/no_unnecessary_condition_test.go | Updates valid/invalid test coverage to match the refactored behavior (including loop-condition modes and OXC-specific cases). |
| internal/rule_tester/snapshots/no-unnecessary-condition.snap | Updates snapshot diagnostics/ranges to match the new rule behavior and test ordering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c58029c to
8d456a3
Compare
01413c2 to
cb3656e
Compare
Merge activity
|
…ation with upstream (#809)
cb3656e to
bf706ba
Compare

No description provided.