-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(typescript-estree): allow projectService to type-check virtual processor children #11827
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
Conversation
|
Thanks for the PR, @CyberT33N! 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. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 3d44e5d
☁️ Nx Cloud last updated this comment at |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11827 +/- ##
=======================================
Coverage 90.53% 90.54%
=======================================
Files 523 523
Lines 53096 53122 +26
Branches 8838 8851 +13
=======================================
+ Hits 48073 48099 +26
Misses 5010 5010
Partials 13 13
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
cea94af to
3d44e5d
Compare
|
Hey thanks for the PR @CyberT33N! You've clearly put a lot of work + thought into this, and it's impressive to see a first PR touch some of the most technically intricate parts of the codebase (typed linting + virtual files). Per the Contributing > Pull Requests guide linked in the PR template that you cleared, we ask that non-trivial PRs only be sent for open, accepted issues. This way we have a chance to discuss the design and desirability of changes before authors like you spend a lot of time implementing. I'll also note that this PR body is very verbose. We have a very limited maintainer bandwidth and deeply reading through the whole thing would take up an unnecessarily large amount of time in it. We're working on docs in #11416 -> #11836. The tl;dr is: regardless of whether you use AI, excessively long descriptions actually harm understandability. Pithiness is good. Please file an ✨ Enhance Another Package issue and fill out the template there so we can have that discussion. I've switched this PR to a draft in the meantime, to remove it from our review queue. To be clear, I'm not saying I/we are against fixing the root issue around virtual children. I've actually hit this problem a lot in my own repos that use both Cheers! |
Thank you very much for taking the time to write such a detailed and kind reply, and for pointing me to the correct contributing / PR process. I now understand that I should first open an ✨ Enhance Another Package issue and only then follow up with a PR, and I’ve done so for this change. I also really appreciate that you’d already been thinking about this area in the context of @eslint/markdown – that background was very helpful to me. |
|
Closing per #11838 (comment). |

This pull request teaches the
@typescript-eslint/typescript-estreeproject-service integration to recognize virtual processor child paths (for exampledocs/example.md/0.tsorfile.mdc/0_0.ts) and automatically treat them as eligible for the TypeScript default project, enabling typed linting for code blocks extracted by processors such as@eslint/markdown.Motivation
Typed linting for code extracted by processors (Markdown/MDX/
.mdcfenced TS blocks) previously failed with errors like:because the TypeScript project service only understood real filesystem paths, whereas ESLint processors only expose virtual child paths (e.g.
file.mdc/0_0.ts) that do not exist on disk and cannot be added totsconfig.json.My original attempt to solve this in ESLint core and
@eslint/markdownwas to introduce aphysicalFilenameconcept and to materialize temporary.tsfiles on disk (see eslint/eslint#20378, eslint/eslint#20375, and eslint/markdown#595). As discussed in the RFC, that pushed responsibility for creating and cleaning up temp files into every processor.In the review discussion, @DMartens pointed out that:
and suggested instead that the TypeScript integration itself (i.e.
@typescript-eslint/parser/typescript-estreevia the Compiler API / project service) should be made aware of virtual child paths.This PR implements that suggestion in
typescript-estree: virtual child paths nested under a real file on disk are detected and automatically allowed to use the default project, without requiring processors to materialize temp files or ESLint core to grow aphysicalFilenameAPI.Type of Change
Detailed Changes
packages/typescript-estree/src/useProgramFromProjectService.ts:isVirtualFilePath(filePathAbsolute: string): booleanthat:falseif the exactfilePathAbsoluteexists on disk.fs.statSync.<project>/docs/example.md/0.ts<project>/rules/EXAMPLE.mdc/0_0.tsfalseon any unexpected error, preserving robustness.useProgramFromProjectService:isDefaultProjectAllowedwas derived solely fromallowDefaultProjectglobs.file.mdc/0_0.tswere not recognized and thus caused “not found by the project service” errors unless manually allow-listed.isDefaultProjectAllowedis computed as:allowDefaultProject.DEFAULT_EXTRA_FILE_EXTENSIONS/extraFileExtensionschecks).reloadProjects) andsingleRunhandling.packages/typescript-estree/tests/lib/useProgramFromProgramService.test.ts:Added a focused unit test:
This test explicitly verifies the new behavior:
allowDefaultProjectglobs configured.path/docs/example.md/0.tswhose parentpath/docs/example.mdis treated as a real file.useProgramFromProjectServicereturns theprogramfrom the project service instead of throwing a “not found by the project service” error.Existing tests around:
allowDefaultProjectglob handling.extraFileExtensions.setHostConfigurationbehavior.remain unchanged and continue to validate the original behaviors.
Testing & Verification
tests/lib/useProgramFromProjectService.test.tsfor virtual child paths under an existing file.useProgramFromProjectServicetest suite continues to pass.@eslint/markdownthat produces virtual child paths (file.md/0.ts,file.mdc/0_0.ts).@typescript-eslint/parserwithparserOptions.projectService: true..mdcfile containing TypeScript code blocks.file.mdc/0_0.ts), preserving existing UX.Breaking Changes (if any)
N/A
This change is designed to be backwards compatible:
allowDefaultProjectbehavior are unchanged.projectService) continue to behave as before.