Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
Relevant Package
typescript-estree
My proposal is suitable for this project
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Description
As reported by @yepitschunked in #8322 (thanks! ❤️🔥):
The current implementation opens all files using the project service, even if the file is not opted into type-aware linting (with the project or programs options).
This makes linting slower than necessary, since project for every file will be loaded.
I like the idea of not calling service.openClientFile
unnecessarily. useProgramFromProjectService
is indeed called always if parseSettings.EXPERIMENTAL_useProjectService
is true:
typescript-eslint/packages/typescript-estree/src/parser.ts
Lines 48 to 53 in 5a1e85d
Logs in #8424 show that opening files with a warmed-up project service to take a few ms per file. That can really add up in projects with many files.
#8322 (comment) shows that avoiding calling service.openClientFile
on files that don't ask for type checking can speed up service-type-checked linting to be on par with traditional type-checked linting. ⚡
Additional Info
Note that I'm not yet convinced that #8322's starting approach is the correct one. That approach only calls openClientFile
on files with type-checked linting enabled. But some users enable type information on all files despite only using it in some. And, heck, type-checked rules only use type checking conditionally - and try to avoid calling it if they can bail out early. So gating openClientFile
on whether a file wants type information can still allow files through the gate unnecessarily.
An alternative possibility might be to avoid opening the client file altogether until getParserServices
is called within a lint rule. I think that's the best possible strategy for avoiding unnecessary openClientFile
calls. But that might require moving all the type generation logic to getParserServices
... which might be good in general? Investigation required.