Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

mdm317
Copy link
Contributor

@mdm317 mdm317 commented May 9, 2025

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.

return vfs.createVirtualTypeScriptEnvironment(

The modules like monaco, typescript, and typescript-website are scattered, so it’s a bit confusing

1. create ts.program by monace

When monaco-editor creating this code will excute link
private _languageService = ts.createLanguageService(this);

createLanguageService in typescript. link

const rootFileNames = host.getScriptFileNames().slice();
 // some code
const options: CreateProgramOptions = {
  rootNames: rootFileNames,
  options: newSettings,
  host: compilerHost, 
  oldProgram: program,
  projectReferences,
};
program = createProgram(options);

And filenames output by getScriptFileNames will be added in the code below.
defaults.addExtraLib(code, path) in typescript-website => defaults.addExtraLib(code, path) in monaco

So, when creating a ts.Program, the rootNames array includes some libraries, such as Node or React.

2. create ts.program by TypeScript-VFS.

const registeredFiles = new Set<string>();
const createEnv = (
compilerOptions: ts.CompilerOptions,
): tsvfs.VirtualTypeScriptEnvironment => {
return vfs.createVirtualTypeScriptEnvironment(
system,
[...registeredFiles],

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 Linting

Testing

  1. Click a link that already has code pre-filled.
  2. Enter code in an empty playground

@typescript-eslint
Copy link
Contributor

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 on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented May 9, 2025

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit f9bd202
🔍 Latest deploy log https://app.netlify.com/projects/typescript-eslint/deploys/682da407195f0a00083babd7
😎 Deploy Preview https://deploy-preview-11198--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

nx-cloud bot commented May 9, 2025

View your CI Pipeline Execution ↗ for commit f9bd202.

Command Status Duration Result
nx typecheck ast-spec ✅ Succeeded <1s View ↗
nx run-many -t build --exclude website website-... ✅ Succeeded 2s View ↗
nx run-many -t clean --parallel=20 ✅ Succeeded 13s View ↗

☁️ Nx Cloud last updated this comment at 2025-05-28 19:08:56 UTC

@kirkwaiblinger kirkwaiblinger changed the title fix(website): Acquired types are shown in the editor but not reflected in linting fix(website): acquired types are shown in the editor but not reflected in linting May 9, 2025
Copy link

codecov bot commented May 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.92%. Comparing base (e57126a) to head (f9bd202).
Report is 56 commits behind head on main.

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           
Flag Coverage Δ
unittest 90.92% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mdm317 mdm317 marked this pull request as ready for review May 21, 2025 16:52
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK! Sorry this PR's review took so long @mdm317. It's quite a tricky change and we had a hard time getting it the time it deserved. But I took a deep dive today and all the comments make sense + were very helpful. Thanks so much for fixing this tricky bug! ❤️

files.set(`/input${config.fileType}`, config.code);
if (config.code !== '') {
files.set(`/input${config.fileType}`, config.code);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question] Why wouldn't we want to set '' for code? What if the user explicitly puts in a blank file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above code is executed when the playground is first loaded.

return vfs.createVirtualTypeScriptEnvironment(
system,
[...registeredFiles],
window.ts,
compilerOptions,

When we set '' for code in the system, a "File '/input.tsx' not found." error occurs in createVirtualTypeScriptEnvironment

If the above code is missing, the playground will not load successfully when the user clicks the playground button in this page

Therefore, we should avoid setting '' fo code in the system.

// if text is empty use empty line to avoid error
const code = text || '\n';

Also, when the user changes the code to '', this code prevents the code field from being set to '' in the system.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that makes sense. Thanks!

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Jun 16, 2025
@JoshuaKGoldberg JoshuaKGoldberg merged commit 76cc62c into typescript-eslint:main Jun 18, 2025
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug(website): Acquired types are shown in the editor but not reflected in linting
2 participants