Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(eslint-plugin): [prefer-optional-chain] suggests optional chaining during strict null equality check #8717

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jsfm01
Copy link
Contributor

@jsfm01 jsfm01 commented Mar 18, 2024

PR Checklist

Overview

The rule suggests replacing logical AND operators (&&) with optional chaining (?.) for checking both object reference and property existence.

However, this substitution can unintentionally alter code logic, especially when separate checks for object existence and property values are needed.
The solution provided skips cases involving strict null equality for these particular cases preventing unintended changes to code logic.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @jsfm01!

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 on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Mar 18, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 27f7269
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/66282f5cc767350008154c24
😎 Deploy Preview https://deploy-preview-8717--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: 99 (🟢 up 6 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (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 your Netlify site configuration.

@jsfm01 jsfm01 marked this pull request as draft March 18, 2024 21:59
Copy link

nx-cloud bot commented Mar 18, 2024

@jsfm01 jsfm01 marked this pull request as ready for review March 22, 2024 15:54
@up201304504 up201304504 force-pushed the fix/7654-prefer-optional-chain branch from ceab321 to 6fb2f03 Compare March 31, 2024 17:23
@bradzacher bradzacher added the bug Something isn't working label Apr 4, 2024
JoshuaKGoldberg
JoshuaKGoldberg previously approved these changes Apr 8, 2024
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! 🎉

Leaving open for a bit since these nullability rules can get tricky. See also: #8559.

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Apr 8, 2024
Copy link

codecov bot commented Apr 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.37%. Comparing base (b0f7aa4) to head (ef31674).

❗ Current head ef31674 differs from pull request most recent head 27f7269. Consider uploading reports for the commit 27f7269 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8717      +/-   ##
==========================================
- Coverage   87.38%   87.37%   -0.02%     
==========================================
  Files         259      255       -4     
  Lines       12581    12503      -78     
  Branches     3930     3925       -5     
==========================================
- Hits        10994    10924      -70     
+ Misses       1313     1304       -9     
- Partials      274      275       +1     
Flag Coverage Δ
unittest 87.37% <100.00%> (-0.02%) ⬇️

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

Files Coverage Δ
.../rules/prefer-optional-chain-utils/analyzeChain.ts 100.00% <100.00%> (ø)
...s/eslint-plugin/src/rules/prefer-optional-chain.ts 97.56% <ø> (-0.06%) ⬇️

... and 30 files with indirect coverage changes

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Swell, thanks!

@JoshuaKGoldberg JoshuaKGoldberg merged commit 4bed24d into typescript-eslint:main Apr 24, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: prefer-optional-chain suggests optional chaining during strict null equality check
4 participants