-
-
Notifications
You must be signed in to change notification settings - Fork 722
Description
ESLint provides various APIs for scope analysis, via SourceCode, and ScopeManager. We need to replicate these APIs in Oxlint JS plugins.
Eventual solution
Eventually we will want to use the scope tree and symbols table that we already build in on Rust side (Scoping struct in oxc_semantic), and transfer it to JS using raw transfer, same as we do for the AST. However, that will be a major undertaking. Challenges include:
- Storing all scoping data in arena and making it available to JS.
- Conforming Oxc's scoping data to ESLint shape.
- Adding more properties to our scope tree which ESLint has, but Oxc doesn't.
- Forking
hashbrown::HashMapto make it transferable. - And much more...
"For now" implementation
The absence of scope analysis APIs is a blocker to running many ESLint plugins in Oxlint at present.
It would be completely unrealistic to overcome all the above challenges in our desired timeframe. So we should try to get it working via an easier method first, with implementation on JS side.
At this stage, performance is not the goal - API coverage is. We should do whatever gets us to a working implementation fastest. We can return to it and improve the perf later on.
How?
The simplest way would likely to be to pull in a dependency.
@typescript-eslint/scope-manager would be ideal, as it includes scopes and symbols for TS types.
However, it's not clear (to me, at least) whether TS-ESLint invokes TypeScript's parser internally to build its scope tree. If so, even though perf is not priority at present, that might be a step too far, as it'd likely be really slow.
Should TS-ESLint's scope manager prove tricky to work with, we could alternatively look at using eslint-scope initially. That would get us at least most of the way.
Where to start?
First task would be research:
- Look into these 2 libraries.
- Figure out how they work.
- Scope out how possible to use them in Oxlint to implement
ScopeManagerinterface, and the other methods currently stubbed out in scope.ts.