Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [no-non-null-asserted-optional-chain] infinite loop problem#5367
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nx-cloudbot commentedJul 24, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for the PR,@YeeJone! 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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitorsper day. |
netlifybot commentedJul 24, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site settings. |
codecovbot commentedJul 24, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ Coverage Diff @@## main #5367 +/- ##==========================================+ Coverage 91.36% 93.82% +2.46%========================================== Files 132 290 +158 Lines 1494 9993 +8499 Branches 226 3009 +2783 ==========================================+ Hits 1365 9376 +8011- Misses 65 336 +271- Partials 64 281 +217
Flags with carried forward coverage won't be shown.Click here to find out more.
|
In an ideal world, this PR would be blocked on#1752, since it adds a couple of logic branches that aren't tested right now. But getting multi-TS-version testing support is going to be pretty tricky. 🤔 |
Indeed, adding multi-TS-version testing capabilities is tricky But this is an obvious problem🐛, and I did some case verification locally with a lower version of TS, and it's fine |
Now I use this package in a project with a low version of TS, and it often gets stuck, which is too uncomfortable😣 |
bradzacher left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this code seems like it's pretty wrong anyways - I don't quite know how (or even if) it ever actually worked to begin with.
the intention is that thebreak
applies to the outerwhile
, but instead it's applying to theswitch
.
The code should instead be like this to explicitly exit the loop.
consthasOptionalChain=(()=>{letcurrent=child;while(current){switch(current.type){caseAST_NODE_TYPES.MemberExpression:if(current.optional){// found an optional chain! stop traversingreturntrue;}current=current.object;continue;caseAST_NODE_TYPES.CallExpression:if(current.optional){// found an optional chain! stop traversingreturntrue;}current=current.callee;continue;default:// something that's not a ChainElement, which means this is not an optional chain we want to checkreturnfalse;}}})();if(!hasOptionalChain){return;}
this is much clearer than the existing code and it explicitly breaks from the loop rather than implicitly exiting
It has been modified, please help to review the code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Could you add some unit tests verifying the behavior please? There are a lot of "line ... was not covered by tests" comments, which are indicating we can't be sure in CI this won't break in the future.
PR Checklist
Overview
Prior to typescript 3.9, the code in the no-non-null-asserted-optional-chain rule had an infinite loop.
Causes the ESLint process to fail to end