Skip to content

refactor(no-unnecessary-condition): more closely align rule implementation with upstream#809

Merged
graphite-app[bot] merged 1 commit into
mainfrom
c/03-18-refactor_no-unnecessary-condition_more_closely_align_rule_implementation_with_upstream
Mar 21, 2026
Merged

refactor(no-unnecessary-condition): more closely align rule implementation with upstream#809
graphite-app[bot] merged 1 commit into
mainfrom
c/03-18-refactor_no-unnecessary-condition_more_closely_align_rule_implementation_with_upstream

Conversation

@camc314

@camc314 camc314 commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@camc314 camc314 marked this pull request as ready for review March 18, 2026 18:36
Copilot AI review requested due to automatic review settings March 18, 2026 18:36

camc314 commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

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.

Copilot AI left a comment

Copy link
Copy Markdown

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

Comment thread internal/rules/no_unnecessary_condition/no_unnecessary_condition.go
Comment thread internal/rules/no_unnecessary_condition/no_unnecessary_condition.go
@camc314 camc314 force-pushed the c/03-18-refactor_no-unnecessary-condition_more_closely_align_rule_implementation_with_upstream branch from a3a8d16 to fdbec03 Compare March 21, 2026 22:28
@camc314 camc314 self-assigned this Mar 21, 2026
@camc314 camc314 requested a review from Copilot March 21, 2026 22:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 allowConstantLoopConditions parsing 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.

Comment thread internal/rules/no_unnecessary_condition/no_unnecessary_condition.go
Comment thread internal/rules/no_unnecessary_condition/no_unnecessary_condition.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@camc314 camc314 force-pushed the c/03-18-refactor_no-unnecessary-condition_more_closely_align_rule_implementation_with_upstream branch from c58029c to 8d456a3 Compare March 21, 2026 23:18
Comment thread internal/rule_tester/__snapshots__/no-unnecessary-condition.snap
Comment thread internal/rule_tester/__snapshots__/no-unnecessary-condition.snap
@camc314 camc314 force-pushed the c/03-18-refactor_no-unnecessary-condition_more_closely_align_rule_implementation_with_upstream branch from 01413c2 to cb3656e Compare March 21, 2026 23:23

camc314 commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

@graphite-app graphite-app Bot force-pushed the c/03-18-refactor_no-unnecessary-condition_more_closely_align_rule_implementation_with_upstream branch from cb3656e to bf706ba Compare March 21, 2026 23:30
@graphite-app graphite-app Bot merged commit bf706ba into main Mar 21, 2026
7 of 8 checks passed
@graphite-app graphite-app Bot removed the 0-merge label Mar 21, 2026
@graphite-app graphite-app Bot deleted the c/03-18-refactor_no-unnecessary-condition_more_closely_align_rule_implementation_with_upstream branch March 21, 2026 23:37
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.

2 participants