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): [explicit-module-boundary-types] cyclical reference infinite recursion crash #2482

Merged

Conversation

@tadhgmister
Copy link
Contributor

@tadhgmister tadhgmister commented Sep 4, 2020

Fixes #2309

the recursive logic added by #2135 is setup to check members that are not directly exported but used by public members of an exported class, for example here A.method needs to be explicit return type because A ends up being exported:

class A {
    method(){}
}
export class B{
    public ref = A;
}

However when the class refers to itself (or any reference loop) this would cause infinite recursion.

To get around this I've just added a set of all nodes we've already visited so recursion will be bounded.

NOTE: it is very possible the checkedFunctions and alreadyVisited sets can be merged. I tried the unit tests where checkFunctions was removed entirely and isExportedHigherOrderFunction used the alreadyVisited set instead, all unit tests passed but it feels unsound since some nodes like the private fields of a class end up added to the visited set so there may be an edge case where, if isExportedHigherOrderFunction used any visited node to detect it's exported, we'd end up with a false positive for requiring annotations. So to be on the safe side I just added a second set.

Tadhg McDonald-Jensen added 2 commits Sep 3, 2020
@typescript-eslint
Copy link

@typescript-eslint typescript-eslint bot commented Sep 4, 2020

Thanks for the PR, @tadhgmister!

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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@codecov
Copy link

@codecov codecov bot commented Sep 4, 2020

Codecov Report

Merging #2482 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2482      +/-   ##
==========================================
+ Coverage   92.82%   92.84%   +0.02%     
==========================================
  Files         289      289              
  Lines        9294     9296       +2     
  Branches     2600     2600              
==========================================
+ Hits         8627     8631       +4     
+ Misses        321      320       -1     
+ Partials      346      345       -1     
Flag Coverage Δ
#unittest 92.84% <100.00%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
...plugin/src/rules/explicit-module-boundary-types.ts 89.26% <100.00%> (+1.50%) ⬆️
@bradzacher bradzacher added the bug label Sep 6, 2020
@bradzacher bradzacher changed the title fix[eslint-plugin]: [explicit-module-boundary-types] cyclical reference no longer fail with infinite recursion fix(eslint-plugin): [explicit-module-boundary-types] cyclical reference infinite recursion crash Sep 6, 2020
Copy link
Member

@bradzacher bradzacher left a comment

ezpz. LGTM - thanks for this.

@bradzacher bradzacher merged commit 8693653 into typescript-eslint:master Sep 6, 2020
10 checks passed
10 checks passed
Typecheck
Details
Unit tests Unit tests
Details
Code style and lint
Details
Run integration tests on primary Node.js version
Details
Run unit tests on other Node.js versions (10.x)
Details
Run unit tests on other Node.js versions (14.x)
Details
Publish the latest code as a canary version
Details
Semantic Pull Request ready to be squashed
Details
codecov/patch Codecov Report
Details
codecov/project Codecov Report
Details
@tadhgmister tadhgmister deleted the tadhgmister:moduleBoundRecursion branch Sep 8, 2020
phaux added a commit to phaux/typescript-eslint that referenced this pull request Sep 28, 2020
…ce infinite recursion crash (typescript-eslint#2482)

Co-authored-by: Tadhg McDonald-Jensen <tadhg.mcdonaldjensen@carleton.ca>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants