Skip to content

Conversation

@ArnaudBarre
Copy link
Owner

@ArnaudBarre ArnaudBarre commented Nov 19, 2025

Implements typescript-eslint/typescript-eslint#8079 that I just had today

Copy link

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 enhances the noUnnecessaryCondition rule to detect useless nullish coalescing patterns where the right-hand side value is already included in the left-hand side type (e.g., x ?? null when x is string | null).

Key Changes:

  • Added detection for redundant ?? null when the left type includes null
  • Added detection for redundant ?? undefined when the left type includes undefined
  • Added auto-fix suggestions to remove unnecessary nullish coalescing

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/rules/noUnnecessaryCondition/noUnnecessaryCondition.ts Added new error messages and logic to detect useless ?? null and ?? undefined patterns, refactored checkNodeForNullish to analyze both sides of the expression
src/rules/noUnnecessaryCondition/noUnnecessaryCondition.test.ts Added test cases for the new functionality and updated existing test assertions with corrected column numbers and new suggestion outputs
CHANGELOG.md Documented the new feature in the unreleased section

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ArnaudBarre ArnaudBarre merged commit cfa955b into main Nov 19, 2025
7 checks passed
@ArnaudBarre ArnaudBarre deleted the catch-more-useless-coalescing branch November 19, 2025 22:33
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