Skip to content
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

fix(eslint-plugin): [prefer-optional-chain] address multipart nullish checks false positive #8678

Merged
merged 1 commit into from Mar 25, 2024

Conversation

kirkwaiblinger
Copy link
Member

PR Checklist

Overview

Basically the trouble is that the rule checks "am I in a subsequence of logical operands that are candidates for optional chaining that is more than one unit long?", assuming that a nullish check will be the first element in that chain and subsequent elements will be chainable expressions. However, a nullish check such as a !== null && a !== undefined takes up more than one element in that subsequence, since it is two comparisons. When checking if the length is greater than 1, we get a false positive.

The code change groups the subsequence so that a !== null && a !== undefined get treated as a single unit when checking whether to report.

my brain hurts.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @kirkwaiblinger!

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 15, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit f2877e7
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/65f392308fdc600008c7f5c8
😎 Deploy Preview https://deploy-preview-8678--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: 98 (🟢 up 5 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.

@kirkwaiblinger kirkwaiblinger changed the title Address grouping of operators in chain fix(eslint-plugin): [prefer-optional-chain] address multipart nullish checks false positive Mar 15, 2024
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.23%. Comparing base (858c9a6) to head (f2877e7).
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8678      +/-   ##
==========================================
+ Coverage   87.21%   87.23%   +0.01%     
==========================================
  Files         251      251              
  Lines       12305    12320      +15     
  Branches     3880     3884       +4     
==========================================
+ Hits        10732    10747      +15     
  Misses       1303     1303              
  Partials      270      270              
Flag Coverage Δ
unittest 87.23% <100.00%> (+0.01%) ⬆️

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%> (ø)

... and 3 files with indirect coverage changes

@kirkwaiblinger kirkwaiblinger marked this pull request as ready for review March 18, 2024 14:48
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.

Wow, what a tricky set of situations. +1 to the implementation, nicely done! 🔥

David Mitchell happily saying 'Brilliant'

@JoshuaKGoldberg JoshuaKGoldberg merged commit 56358a6 into typescript-eslint:main Mar 25, 2024
61 of 62 checks passed
@kirkwaiblinger kirkwaiblinger deleted the 8380-clean branch March 25, 2024 16:17
peanutenthusiast pushed a commit to peanutenthusiast/typescript-eslint that referenced this pull request Mar 27, 2024
… checks false positive (typescript-eslint#8678)

Address grouping of operators in chain
yeonjuan pushed a commit to yeonjuan/typescript-eslint that referenced this pull request Mar 31, 2024
… checks false positive (typescript-eslint#8678)

Address grouping of operators in chain
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [prefer-optional-chain] Issue with check on null and undefined
2 participants