Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): do not suggest unsafe optional-chain + strict null in prefer-optional-chain#11844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
BeauRussell wants to merge3 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
fromBeauRussell:fix/11840

Conversation

@BeauRussell
Copy link

PR Checklist

Overview

Theprefer-optional-chain rule was suggesting an unsafe transformation when an OR-chain mixed a strict=== undefined check with a strict=== null check on a property access.

The Problem

Given:

if(foo===undefined||foo.bar===null){ ...}

The rule suggested:foo?.bar === null

This isnot equivalent because optional chaining returnsundefined for nullish receivers, so whenfoo isundefined, the rewritten condition evaluates tofalse instead oftrue, changing control flow.

The Fix

The rule now reports the pattern but does not offer a fix/suggestion when:

  • An OR-chain contains a strict=== undefined check
  • The suggested rewrite would be an optional-chain with strict=== null /!== null

This prevents the unsafe transformation while preserving valid suggestions (e.g., when using loose equality or when all checks are for the same literal).

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@BeauRussell!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint.

@netlify
Copy link

netlifybot commentedDec 15, 2025
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit5810d95
🔍 Latest deploy loghttps://app.netlify.com/projects/typescript-eslint/deploys/6940011fa986040008511981
😎 Deploy Previewhttps://deploy-preview-11844--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 90 (🔴 down 7 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to yourNetlify project configuration.

@nx-cloud
Copy link

nx-cloudbot commentedDec 15, 2025
edited
Loading

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable themin workspace settings.


View yourCI Pipeline Execution ↗ for commit5810d95

CommandStatusDurationResult
nx test eslint-plugin --coverage=false❌ Failed5m 18sView ↗
nx test eslint-plugin❌ Failed5m 13sView ↗
nx run-many -t lint✅ Succeeded3m 19sView ↗
nx run-many -t typecheck✅ Succeeded2m 1sView ↗
nx run generate-configs✅ Succeeded7sView ↗
nx test typescript-estree --coverage=false✅ Succeeded2sView ↗
nx run integration-tests:test✅ Succeeded3sView ↗
nx run types:build✅ Succeeded2sView ↗
Additional runs (28)✅ Succeeded...View ↗

☁️Nx Cloud last updated this comment at2025-12-15 12:45:55 UTC

@codecov
Copy link

codecovbot commentedDec 15, 2025
edited
Loading

Codecov Report

❌ Patch coverage is95.12195% with2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.58%. Comparing base (1301f79) to head (09cab3e).

⚠️Current head09cab3e differs from pull request most recent head5810d95

Pleaseupload reports for the commit5810d95 to get more accurate results.

Files with missing linesPatch %Lines
.../rules/prefer-optional-chain-utils/analyzeChain.ts95.12%2 Missing⚠️
Additional details and impacted files
@@           Coverage Diff           @@##             main   #11844   +/-   ##=======================================  Coverage   90.58%   90.58%           =======================================  Files         524      524             Lines       53324    53365   +41       Branches     8892     8912   +20     =======================================+ Hits        48301    48340   +39- Misses       5010     5012    +2  Partials       13       13
FlagCoverage Δ
unittest90.58% <95.12%> (+<0.01%)⬆️

Flags with carried forward coverage won't be shown.Click here to find out more.

Files with missing linesCoverage Δ
.../rules/prefer-optional-chain-utils/analyzeChain.ts99.64% <95.12%> (-0.36%)⬇️
🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@BeauRussellBeauRussell marked this pull request as draftDecember 15, 2025 13:00
@BeauRussell
Copy link
Author

Going to take a minute and make this more robust to handle && !== as well as reverse versions

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Bug: [prefer-optional-chain] unsafe fix when the chain ends with a null comparison (a.b === null)

1 participant

@BeauRussell

[8]ページ先頭

©2009-2025 Movatter.jp