Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Why does@typescript-eslint/parser not use the linted code's TypeScript package#6031

Closed
WesCossick started this conversation inTechnical Discussions
Discussion options

RFC

In#3293, I identified a problem where the location of the@typescript-eslint/parser package in relation to the linted code seemed to affect how it behaved. It was determined that when@typescript-eslint/parser doesrequire('typescript'), it retrieves the version of TypeScript that's nearest to the@typescript-eslint/parser package, which might be different than the version of TypeScript used by the code being linted.

During development on one of our internal tools, this exact issue cropped up again, causing us to revisit#3293. That led me to wonder... why does@typescript-eslint/parser use its owntypescript package instead of the one used by the code being linted?

In our case, thetypescript package our linted code was using was being patched by Yarn's Plug'n'Play feature, but I imagine that other differences could crop up simply between different versions of TypeScript. Should@typescript-eslint/parser be using the version of TypeScript it finds when searching from the directory that holds the file/code being linted instead?

Additional Info

No response

Before you submit your RFC, please confirm the following. If any of these required steps are not taken, we may not be able to review your RFC. Help us to help you!

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

The short answer is no - because we need to use the exact same TS version everywhere and we need to make sure that everyone uses th exact same TS version everywhere, which would be a very high effort project to do, which (frankly) isn't something worth doing to solve for this really rare usecase.


We control the parser, we control one eslint plugin. But there are many other plugins that exist using type information.
Additionally there are many utility packages (liketsutils or@typescript-eslint/type-utils) that are consumed by plugins.

In order to make this world of "consume TS from the file's directory" work we would have to:

  1. traverse the disk for every single file being linted in order to find the TS module
    • this is slow and will kill lint times - disk ops are slow!
  2. rewrite our infra to use this specific version.
    • doable, just going to be a high cost exercise.
    • would require new lint rules to help prevent regressions.
  3. pass that TS instance around from the parser to plugins
    • easy enough, sure, we can pass it via parserServices probs.
  4. ensure that every plugin uses that exact TS instance and no other one.
    • now this is a massive breaking change and something that's going to be really, really hard to enforce.
  5. rewrite every utility package so that it accepts its TS module dependency as an argument in some way so that it uses the exact TS instance.
    • impossible to do - util packages just assume they canrequire('typescript'). Who are we to force them to breaking change their entire API surface?
    • so we fork the utility ecosystem? Very, very high cost and ongoing maintenance cost.
    • tying back to (4) - going to be very hard to enforce everyone only uses utils that respect this world.

Hopefully this helps shed some light on the large complexities that are involved in making the ecosystem work like this.

As I said - the cost is monumentally high and has large ongoing maintenance costs. Such a cost is too great to pay to solve the very, very unique problem.

Generally the solution would be to colocate your linting install and your code install so they have the exact same version. Failing that ensuring that the TS version is synced / enforced via some CI check should be fine.
If you can't colocate but you need the installs to be the exact same physical install, then you're really in a truly unique situation.

You must be logged in to vote
1 reply
@WesCossick
Comment options

I was traveling last week, but wanted to thank you for taking the time to explain this so thoroughly. I realize our situation is atypical, but I wanted to post about it in case it was a simple change, since on the surface it seemed like it could be an improvement. Doesn't sound like it's worth the complexity, though, which is understandable.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
None yet
2 participants
@WesCossick@bradzacher

[8]ページ先頭

©2009-2025 Movatter.jp