Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(website): acquired types are shown in the editor but not reflected in linting#11198
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
fix(website): acquired types are shown in the editor but not reflected in linting#11198
Conversation
Thanks for the PR,@mdm317! 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 onhttps://opencollective.com/typescript-eslint. |
netlifybot commentedMay 9, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify project configuration. |
nx-cloudbot commentedMay 9, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
View yourCI Pipeline Execution ↗ for commitf9bd202.
☁️Nx Cloud last updated this comment at |
codecovbot commentedMay 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@## main #11198 +/- ##======================================= Coverage 90.91% 90.92% ======================================= Files 499 499 Lines 50809 50847 +38 Branches 8369 8384 +15 =======================================+ Hits 46195 46233 +38 Misses 4599 4599 Partials 15 15
Flags with carried forward coverage won't be shown.Click here to find out more. 🚀 New features to boost your workflow:
|
system.getScriptFileNames = (): string[] => { | ||
return [...files.keys()] | ||
.filter(fileName => !fileName.startsWith('/lib.')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Lib files will be excluded from the Monaco Editor GitHub repository.monaco-editor
const models = allModels.filter((uri) => !fileNameIsLib(uri)).map((uri) => uri.toString());
system.getScriptFileNames = (): string[] => { | ||
return [...files.keys()] | ||
.filter(fileName => !fileName.startsWith('/lib.')) | ||
.filter(f => !f.endsWith('/.eslintrc') && !f.endsWith('.json')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
These files cause an error in the code below.typescript-website
if (diagnostics.length) { const compilerHost = createVirtualCompilerHost(sys, compilerOptions, ts) throw new Error(ts.formatDiagnostics(diagnostics, compilerHost.compilerHost)) }
registerFile(filePath: string, code: string): void { | ||
compilerHost.createFile(filePath, code); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We have to add library files usingcompilerHost.createFile
, because adding them directly to thesystem
doesn't make them appear ingetScriptFileNames
, and thus they aren't included in therootNames
when creating program.typescript-website
export function createVirtualLanguageServiceHost( sys: System, rootFiles: string[], compilerOptions: CompilerOptions, ts: TS, customTransformers?: CustomTransformers) { const fileNames = [...rootFiles] ...somecode const languageServiceHost: LanguageServiceHost = { getScriptFileNames: () => fileNames.slice(), } ...somecode}
const registerFile = (fileName: string, code: string) => { | ||
parser.registerFile(fileName, code); | ||
triggerLintAll(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We need this code to add the library and trigger linting after the parser is created, in case the user starts typing code in an empty playground.
Uh oh!
There was an error while loading.Please reload this page.
PR Checklist
Overview
I think this issue occurs because of differences in the properties used when creating a ts.Program between Monaco and TypeScript-VFS.
The modules likemonaco, [typescript]
(https://github.com/microsoft/TypeScript), andtypescript-website are scattered, so it’s a bit confusing
1. create
ts.program
by monaceWhen monaco-editor creating this code will excutelink
private _languageService = ts.createLanguageService(this);
createLanguageService in typescript.link
And filenames output by
getScriptFileNames
will be added in the code below.defaults.addExtraLib(code, path)
intypescript-website =>defaults.addExtraLib(code, path)
inmonacoSo, when creating a ts.Program, the rootNames array includes some libraries, such as Node or React.
2. create
ts.program
by TypeScript-VFS.Unlike case 1 above,We don't pass the name of a node_modules folder in fileNames.
In the sentence above, I modified it so that rootNames are provided when creating the
ts.Program
for both the Editor and LintingTesting