Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
mdm317 wants to merge3 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
frommdm317:11120-acquired-types-not-in-linting
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,12 +6,13 @@ import semverSatisfies from 'semver/functions/satisfies';

import type { createTypeScriptSandbox } from '../../vendor/sandbox';
import type { CreateLinter } from '../linter/createLinter';
import type { PlaygroundSystem } from '../linter/types';
import type { PlaygroundSystem, RegisterFile } from '../linter/types';
import type { RuleDetails } from '../types';
import type { CommonEditorProps } from './types';

import rootPackageJson from '../../../../../package.json';
import { createCompilerOptions } from '../lib/createCompilerOptions';
import { createEventsBinder } from '../lib/createEventsBinder';
import { createFileSystem } from '../linter/bridge';
import { createLinter } from '../linter/createLinter';
import { createTwoslashInlayProvider } from './createProvideTwoslashInlay';
Expand DownExpand Up@@ -79,6 +80,7 @@ export const useSandboxServices = (
sandboxInstance.language,
createTwoslashInlayProvider(sandboxInstance),
);
const onModelCreate = createEventsBinder<RegisterFile>();

const system = createFileSystem(props, sandboxInstance.tsvfs);

Expand All@@ -89,6 +91,7 @@ export const useSandboxServices = (
}
const path = model.uri.path.replace('/file:///', '/');
system.writeFile(path, model.getValue());
onModelCreate.trigger(path, model.getValue());
});
// Delete files in vfs when a model is disposed in the editor (this is used only for ATA types)
sandboxInstance.monaco.editor.onWillDisposeModel(model => {
Expand DownExpand Up@@ -117,6 +120,7 @@ export const useSandboxServices = (
lintUtils,
sandboxInstance.tsvfs,
);
onModelCreate.register(webLinter.registerFile);

onLoaded(
[...webLinter.rules.values()],
Expand Down
10 changes: 8 additions & 2 deletionspackages/website/src/components/linter/bridge.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,9 @@ export function createFileSystem(
const files = new Map<string, string>();
files.set(`/.eslintrc`, config.eslintrc);
files.set(`/tsconfig.json`, config.tsconfig);
files.set(`/input${config.fileType}`, config.code);
if (config.code !== '') {
files.set(`/input${config.fileType}`, config.code);
}

const fileWatcherCallbacks = new Map<RegExp, Set<ts.FileWatcherCallback>>();

Expand DownExpand Up@@ -78,6 +80,10 @@ export function createFileSystem(
const expPath = getPathRegExp(path);
return [...files.keys()].filter(fileName => expPath.test(fileName));
};

system.getScriptFileNames = (): string[] => {
return [...files.keys()]
.filter(fileName => !fileName.startsWith('/lib.'))
Copy link
ContributorAuthor

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());

.filter(f => !f.endsWith('/.eslintrc') && !f.endsWith('.json'));
Copy link
ContributorAuthor

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))  }

};
return system;
}
8 changes: 8 additions & 0 deletionspackages/website/src/components/linter/createLinter.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,7 @@ import type {
LinterOnLint,
LinterOnParse,
PlaygroundSystem,
RegisterFile,
WebLinterModule,
} from './types';

Expand All@@ -36,6 +37,7 @@ export interface CreateLinter {
triggerFix(filename: string): Linter.FixReport | undefined;
triggerLint(filename: string): void;
updateParserOptions(sourceType?: SourceType): void;
registerFile: RegisterFile;
}

export function createLinter(
Expand DownExpand Up@@ -164,6 +166,11 @@ export function createLinter(
}
};

const registerFile = (fileName: string, code: string) => {
parser.registerFile(fileName, code);
triggerLintAll();
};
Comment on lines +169 to +172
Copy link
ContributorAuthor

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.


const triggerLintAll = (): void => {
system.searchFiles('/input.*').forEach(triggerLint);
};
Expand All@@ -185,6 +192,7 @@ export function createLinter(
configs: [...configs.keys()],
onLint: onLint.register,
onParse: onParse.register,
registerFile,
rules,
triggerFix,
triggerLint,
Expand Down
12 changes: 7 additions & 5 deletionspackages/website/src/components/linter/createParser.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@ import type * as ts from 'typescript';
import type {
ParseSettings,
PlaygroundSystem,
RegisterFile,
UpdateModel,
WebLinterModule,
} from './types';
Expand All@@ -20,15 +21,14 @@ export function createParser(
vfs: typeof tsvfs,
): {
updateConfig: (compilerOptions: ts.CompilerOptions) => void;
registerFile: RegisterFile;
} & Parser.ParserModule {
const registeredFiles = new Set<string>();

const createEnv = (
compilerOptions: ts.CompilerOptions,
): tsvfs.VirtualTypeScriptEnvironment => {
return vfs.createVirtualTypeScriptEnvironment(
system,
[...registeredFiles],
system.getScriptFileNames(),
window.ts,
compilerOptions,
);
Expand All@@ -46,10 +46,9 @@ export function createParser(
// if text is empty use empty line to avoid error
const code = text || '\n';

if (registeredFiles.has(filePath)) {
if (system.fileExists(filePath)) {
compilerHost.updateFile(filePath, code);
} else {
registeredFiles.add(filePath);
compilerHost.createFile(filePath, code);
}

Expand DownExpand Up@@ -108,6 +107,9 @@ export function createParser(
visitorKeys: utils.visitorKeys,
};
},
registerFile(filePath: string, code: string): void {
compilerHost.createFile(filePath, code);
},
Comment on lines +110 to +112
Copy link
ContributorAuthor

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}

updateConfig(compilerOptions): void {
compilerHost = createEnv(compilerOptions);
},
Expand Down
3 changes: 3 additions & 0 deletionspackages/website/src/components/linter/types.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,6 +30,7 @@ export interface WebLinterModule {
export type PlaygroundSystem = {
removeFile: (fileName: string) => void;
searchFiles: (path: string) => string[];
getScriptFileNames: () => string[];
} & Required<Pick<ts.System, 'deleteFile' | 'watchFile'>> &
ts.System;

Expand All@@ -39,3 +40,5 @@ export type LinterOnLint = (
) => void;

export type LinterOnParse = (fileName: string, model: UpdateModel) => void;

export type RegisterFile = (fileName: string, code: string) => void;

[8]ページ先頭

©2009-2025 Movatter.jp