Skip to content

WIP: feat(eslint-plugin): migrate no-unnecessary-generics from dtslint #3756

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

Closed
wants to merge 4 commits into from

Conversation

Zzzen
Copy link
Contributor

@Zzzen Zzzen commented Aug 19, 2021

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @Zzzen!

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.

@bradzacher bradzacher added the enhancement: new plugin rule New rule request for eslint-plugin label Aug 20, 2021
@bradzacher bradzacher marked this pull request as draft August 20, 2021 06:06
}
}

function forEachType(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

● no-unnecessary-generics › valid ›

function f1<T extends { new (...args: any[]): any }>(a: T) {
  return class Foo extends a {
    f = 1;
  };
}
RangeError: Maximum call stack size exceeded
Occurred while linting typescript-eslint/packages/eslint-plugin/tests/fixtures/file.ts:2

  250 |         });
  251 |
> 252 |         forEachType(signature.getReturnType(), cb, checker);
      |                               ^
  253 |
  254 |         // const predicate = checker.getTypePredicateOfSignature();
  255 |         const decl = signature?.getDeclaration();

It seems checking if a type is used in another type is extremely difficult. Even an innocent constructor signature may kill the linter.

Copy link
Member

Choose a reason for hiding this comment

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

Is there another way to get this info?
There must be otherwise TS would always die for that sort of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I have found why it is crashing.
To check if type T is used in any[], we need to check every member/method of any[].

interface Array<T> {
    length: number;
    concat(...items: Array<ConcatArray<T>>);
}

Apparently, the definition of Array is recursive, which spans Array<ConcatArray<...<ConcatArray<ConcatArray<T>>>...>>

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Oct 3, 2021
@JoshuaKGoldberg
Copy link
Member

👋 @Zzzen, just checking in! Do you still have interest + time for this PR?

No worries if not!

@Zzzen
Copy link
Contributor Author

Zzzen commented Jan 24, 2022

🥲 It's much more complicated than I have expected. It would be great if someone else can implement it.

@bradzacher bradzacher added the help wanted Extra attention is needed label Jan 24, 2022
@bradzacher bradzacher added the stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period label Mar 4, 2022
@bradzacher
Copy link
Member

I'll close this for housekeeping purposes.
Anyone is free to pickup this PR and raise a fresh one with the changes should they want to continue this work!

@bradzacher bradzacher closed this Mar 4, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party enhancement: new plugin rule New rule request for eslint-plugin help wanted Extra attention is needed stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants