Skip to content

Bug: typeMatchesSpecifier FileSpecifier checks in node modules #6819

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

Open
4 tasks done
RebeccaStevens opened this issue Apr 2, 2023 · 8 comments
Open
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working

Comments

@RebeccaStevens
Copy link
Contributor

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

utils

Playground Link

No response

Repro Code

typeMatchesSpecifier(
  type,
  {
    from: "file",
    name: "RegExp",
  },
  parserServices.program)

ESLint Config

No response

tsconfig

No response

Expected Result

It shouldn't find this type (as I haven't defined it).

Actual Result

I finds it in "node_modules/.pnpm/typescript@5.0.3/node_modules/typescript/lib/lib.es5.d.ts".

Additional Info

I would expect a FileSpecifier to ignore node module files by default.
typescript/lib/*.d.ts files should only match with a LibSpecifier and other files in node module to only match with a PackageSpecifier.

Maybe FileSpecifier needs an extra property like ignorePath or ignoreGlob that defaults to "node_modules".
Or alternatively, path could be made a glob that defaults to selecting files not in "node_modules".

Versions

package version
@typescript-eslint/eslint-plugin 6.0.0-alpha.106
@typescript-eslint/parser 6.0.0-alpha.106
@typescript-eslint/scope-manager 6.0.0-alpha.106
@typescript-eslint/typescript-estree 6.0.0-alpha.106
@typescript-eslint/type-utils 6.0.0-alpha.106
@typescript-eslint/utils 6.0.0-alpha.106
TypeScript 5.0.3
ESLint 8.36.0
node 18.15.0
@RebeccaStevens RebeccaStevens added bug Something isn't working triage Waiting for team members to take a look labels Apr 2, 2023
@JoshuaKGoldberg
Copy link
Member

🤔 @RebeccaStevens I think this makes sense. But similar to #6818 - is there a more full repro you can provide?

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Apr 2, 2023
@RebeccaStevens
Copy link
Contributor Author

I made a repo here: https://github.com/RebeccaStevens/typescript-eslint-issue-6818
The invalid test is failing.

The test rule I setup simply reports if typeMatchesSpecifier returns false for a parameter type.

I also found another strange issue when setting this up. I tried using Set for this test instead of RegExp, but the Set type would only find the default lib Set, and not the custom one.

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed awaiting response Issues waiting for a reply from the OP or another party labels Apr 3, 2023
@RebeccaStevens
Copy link
Contributor Author

@marekdedic

@marekdedic
Copy link
Contributor

marekdedic commented Apr 7, 2023

Hi,
yeah, this makes sense.

I propose to think about the behaviour in the two situations separately:

  1. The FileSpecifier doesn't contain a path. In this case, I think it makes sense not to match anything in node_modules

  2. It does - well, I can go either way. I mean, you really should be using PackageSpecifier so I am OK with disallowing node_modules, but if you explicitly specify a path in node_modules, well, you seem to be misusing this intentionally...

Anyway, I'll try to make a PR.

@RebeccaStevens
Copy link
Contributor Author

@marekdedic Just beat you to it 😛

@RebeccaStevens
Copy link
Contributor Author

I should probably open a new issue for this, but should we add the ability to specify a partial path?

So for example:

{ from: "file", name: "Foo", path: "src" }

Will match any Foo where there exists a type definition for it in a file that starts with program.getCurrentDirectory().toLowerCase() + "src".

This will act similarly to how when no path is given, the file must start with program.getCurrentDirectory().toLowerCase().

@JoshuaKGoldberg
Copy link
Member

I should probably open a new issue for this

Yes please 😇

@marekdedic
Copy link
Contributor

marekdedic commented Apr 7, 2023

Well or maybe this should be a part of #6839 ?

@JoshuaKGoldberg JoshuaKGoldberg changed the title Bug: v6 typeMatchesSpecifier FileSpecifier checks in node modules Bug: typeMatchesSpecifier FileSpecifier checks in node modules Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working
Projects
None yet
3 participants