diff --git a/.vscode/launch.json b/.vscode/launch.json index 35c5c3194ec3..1c2b4b3dd803 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,6 +18,20 @@ "sourceMaps": true, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Run currently opened typescript-estree test", + "cwd": "${workspaceFolder}/packages/typescript-estree/", + "program": "${workspaceFolder}/node_modules/jest/bin/jest.js", + "args": [ + "--runInBand", + "${relativeFile}" + ], + "sourceMaps": true, + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" } ] } diff --git a/packages/parser/README.md b/packages/parser/README.md index 042fb4f5f540..9fcb9d043633 100644 --- a/packages/parser/README.md +++ b/packages/parser/README.md @@ -66,7 +66,9 @@ The following additional configuration options are available by specifying them ]; ``` - - Note that if you use project references, TypeScript will not automatically use project references to resolve files. This means that you will have to add each referenced tsconfig to the `project` field either separately, or via a glob. + - If you use project references, TypeScript will not automatically use project references to resolve files. This means that you will have to add each referenced tsconfig to the `project` field either separately, or via a glob. + + - TypeScript will ignore files with duplicate filenames in the same folder (for example, `src/file.ts` and `src/file.js`). TypeScript purposely ignore all but one of the files, only keeping the one file with the highest priority extension (the extension priority order (from highest to lowest) is `.ts`, `.tsx`, `.d.ts`, `.js`, `.jsx`). For more info see #955. - Note that if this setting is specified and `createDefaultProgram` is not, you must only lint files that are included in the projects as defined by the provided `tsconfig.json` files. If your existing configuration does not include all of the files you would like to lint, you can create a separate `tsconfig.eslint.json` as follows: diff --git a/packages/typescript-estree/src/WatchCompilerHostOfConfigFile.ts b/packages/typescript-estree/src/WatchCompilerHostOfConfigFile.ts new file mode 100644 index 000000000000..7fb4663b985c --- /dev/null +++ b/packages/typescript-estree/src/WatchCompilerHostOfConfigFile.ts @@ -0,0 +1,37 @@ +// These types are internal to TS. +// They have been trimmed down to only include the relevant bits +// We use some special internal TS apis to help us do our parsing flexibly + +import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports + +// https://github.com/microsoft/TypeScript/blob/b84e65db4ea5c39dbaa2ccd6594efe4653318251/src/compiler/watchUtilities.ts#L6-L18 +interface DirectoryStructureHost { + readDirectory?( + path: string, + extensions?: ReadonlyArray, + exclude?: ReadonlyArray, + include?: ReadonlyArray, + depth?: number, + ): string[]; +} + +// https://github.com/microsoft/TypeScript/blob/b84e65db4ea5c39dbaa2ccd6594efe4653318251/src/compiler/watchUtilities.ts#L25-L35 +interface CachedDirectoryStructureHost extends DirectoryStructureHost { + readDirectory( + path: string, + extensions?: ReadonlyArray, + exclude?: ReadonlyArray, + include?: ReadonlyArray, + depth?: number, + ): string[]; +} + +// https://github.com/microsoft/TypeScript/blob/5d36aab06f12b0a3ba6197eb14e98204ec0195fb/src/compiler/watch.ts#L548-L554 +interface WatchCompilerHostOfConfigFile + extends ts.WatchCompilerHostOfConfigFile { + onCachedDirectoryStructureHostCreate( + host: CachedDirectoryStructureHost, + ): void; +} + +export { WatchCompilerHostOfConfigFile }; diff --git a/packages/typescript-estree/src/tsconfig-parser.ts b/packages/typescript-estree/src/tsconfig-parser.ts index 364dd0543c8e..e6ef356b6f30 100644 --- a/packages/typescript-estree/src/tsconfig-parser.ts +++ b/packages/typescript-estree/src/tsconfig-parser.ts @@ -1,6 +1,7 @@ import path from 'path'; import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports import { Extra } from './parser-options'; +import { WatchCompilerHostOfConfigFile } from './WatchCompilerHostOfConfigFile'; //------------------------------------------------------------------------------ // Environment calculation @@ -13,6 +14,8 @@ export const defaultCompilerOptions: ts.CompilerOptions = { allowNonTsExtensions: true, allowJs: true, checkJs: true, + noEmit: true, + // extendedDiagnostics: true, }; /** @@ -115,7 +118,7 @@ export function calculateProjectParserOptions( ts.createSemanticDiagnosticsBuilderProgram, diagnosticReporter, /*reportWatchStatus*/ () => {}, - ); + ) as WatchCompilerHostOfConfigFile; // ensure readFile reads the code being linted instead of the copy on disk const oldReadFile = watchCompilerHost.readFile; @@ -144,8 +147,7 @@ export function calculateProjectParserOptions( }; // register callbacks to trigger program updates without using fileWatchers - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - watchCompilerHost.watchFile = (fileName, callback) => { + watchCompilerHost.watchFile = (fileName, callback): ts.FileWatcher => { const normalizedFileName = path.normalize(fileName); watchCallbackTrackingMap.set(normalizedFileName, callback); return { @@ -156,26 +158,20 @@ export function calculateProjectParserOptions( }; // ensure fileWatchers aren't created for directories - watchCompilerHost.watchDirectory = (): typeof noopFileWatcher => - noopFileWatcher; + watchCompilerHost.watchDirectory = (): ts.FileWatcher => noopFileWatcher; - // we're using internal typescript APIs which aren't on the types - /* eslint-disable @typescript-eslint/no-explicit-any */ // allow files with custom extensions to be included in program (uses internal ts api) - const oldOnDirectoryStructureHostCreate = (watchCompilerHost as any) - .onCachedDirectoryStructureHostCreate; - (watchCompilerHost as any).onCachedDirectoryStructureHostCreate = ( - host: any, - ): void => { + const oldOnDirectoryStructureHostCreate = + watchCompilerHost.onCachedDirectoryStructureHostCreate; + watchCompilerHost.onCachedDirectoryStructureHostCreate = (host): void => { const oldReadDirectory = host.readDirectory; - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type host.readDirectory = ( - path: string, - extensions?: readonly string[], - exclude?: readonly string[], - include?: readonly string[], - depth?: number, - ) => + path, + extensions, + exclude, + include, + depth, + ): string[] => oldReadDirectory( path, !extensions @@ -187,7 +183,6 @@ export function calculateProjectParserOptions( ); oldOnDirectoryStructureHostCreate(host); }; - /* eslint-enable @typescript-eslint/no-explicit-any */ // create program const programWatch = ts.createWatchProgram(watchCompilerHost); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy