From 2004a86fc26992a6e5e81b694ec1ecb624c7e270 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 4 Apr 2024 03:21:17 +0100 Subject: [PATCH 1/2] feat(typescript-estree): remove slow deprecated and isolated programs --- docs/packages/TypeScript_ESTree.mdx | 6 -- .../create-program/createDefaultProgram.ts | 72 ------------------- .../create-program/createProjectProgram.ts | 4 +- .../src/parseSettings/createParseSettings.ts | 3 - .../src/parseSettings/index.ts | 7 -- .../typescript-estree/src/parser-options.ts | 6 -- packages/typescript-estree/src/parser.ts | 17 +---- .../tests/lib/semanticInfo.test.ts | 9 --- .../website/src/components/linter/config.ts | 1 - 9 files changed, 3 insertions(+), 122 deletions(-) delete mode 100644 packages/typescript-estree/src/create-program/createDefaultProgram.ts diff --git a/docs/packages/TypeScript_ESTree.mdx b/docs/packages/TypeScript_ESTree.mdx index f589cb8f6605..6801710a361a 100644 --- a/docs/packages/TypeScript_ESTree.mdx +++ b/docs/packages/TypeScript_ESTree.mdx @@ -235,12 +235,6 @@ interface ParseAndGenerateServicesOptions extends ParseOptions { */ programs?: Program[]; - /** - * @deprecated - this flag will be removed in the next major. - * Do not rely on the behavior provided by this flag. - */ - DEPRECATED__createDefaultProgram?: boolean; - /** * ESLint (and therefore typescript-eslint) is used in both "single run"/one-time contexts, * such as an ESLint CLI invocation, and long-running sessions (such as continuous feedback diff --git a/packages/typescript-estree/src/create-program/createDefaultProgram.ts b/packages/typescript-estree/src/create-program/createDefaultProgram.ts deleted file mode 100644 index b42ec76c678b..000000000000 --- a/packages/typescript-estree/src/create-program/createDefaultProgram.ts +++ /dev/null @@ -1,72 +0,0 @@ -import debug from 'debug'; -import path from 'path'; -import * as ts from 'typescript'; - -import type { ParseSettings } from '../parseSettings'; -import type { ASTAndDefiniteProgram } from './shared'; -import { createDefaultCompilerOptionsFromExtra } from './shared'; - -const log = debug('typescript-eslint:typescript-estree:createDefaultProgram'); - -/** - * @param parseSettings Internal settings for parsing the file - * @returns If found, returns the source file corresponding to the code and the containing program - * @deprecated - * This is a legacy option that comes with severe performance penalties. - * Please do not use it. - */ -function createDefaultProgram( - parseSettings: ParseSettings, -): ASTAndDefiniteProgram | undefined { - log( - 'Getting default program for: %s', - parseSettings.filePath || 'unnamed file', - ); - - if (parseSettings.projects.length !== 1) { - return undefined; - } - - const tsconfigPath = parseSettings.projects[0]; - - const commandLine = ts.getParsedCommandLineOfConfigFile( - tsconfigPath, - createDefaultCompilerOptionsFromExtra(parseSettings), - { - ...ts.sys, - // TODO: file issue on TypeScript to suggest making optional? - // eslint-disable-next-line @typescript-eslint/no-empty-function - onUnRecoverableConfigFileDiagnostic: () => {}, - }, - ); - - if (!commandLine) { - return undefined; - } - - const compilerHost = ts.createCompilerHost( - commandLine.options, - /* setParentNodes */ true, - ); - - const oldReadFile = compilerHost.readFile; - compilerHost.readFile = (fileName: string): string | undefined => - path.normalize(fileName) === path.normalize(parseSettings.filePath) - ? parseSettings.codeFullText - : oldReadFile(fileName); - - const program = ts.createProgram( - [parseSettings.filePath], - { - ...commandLine.options, - jsDocParsingMode: parseSettings.jsDocParsingMode, - }, - compilerHost, - ); - const ast = program.getSourceFile(parseSettings.filePath); - - return ast && { ast, program }; -} - -// eslint-disable-next-line deprecation/deprecation -- will be cleaned up with the next major -export { createDefaultProgram }; diff --git a/packages/typescript-estree/src/create-program/createProjectProgram.ts b/packages/typescript-estree/src/create-program/createProjectProgram.ts index a58097e3cd73..4b8955c28c41 100644 --- a/packages/typescript-estree/src/create-program/createProjectProgram.ts +++ b/packages/typescript-estree/src/create-program/createProjectProgram.ts @@ -28,7 +28,7 @@ const DEFAULT_EXTRA_FILE_EXTENSIONS = [ function createProjectProgram( parseSettings: ParseSettings, programsForProjects: readonly ts.Program[], -): ASTAndDefiniteProgram | undefined { +): ASTAndDefiniteProgram { log('Creating project program for: %s', parseSettings.filePath); const astAndProgram = firstDefined(programsForProjects, currentProgram => @@ -37,7 +37,7 @@ function createProjectProgram( // The file was either matched within the tsconfig, or we allow creating a default program // eslint-disable-next-line deprecation/deprecation -- will be cleaned up with the next major - if (astAndProgram || parseSettings.DEPRECATED__createDefaultProgram) { + if (astAndProgram) { return astAndProgram; } diff --git a/packages/typescript-estree/src/parseSettings/createParseSettings.ts b/packages/typescript-estree/src/parseSettings/createParseSettings.ts index 49d048391d8f..210da9bcb042 100644 --- a/packages/typescript-estree/src/parseSettings/createParseSettings.ts +++ b/packages/typescript-estree/src/parseSettings/createParseSettings.ts @@ -68,9 +68,6 @@ export function createParseSettings( codeFullText, comment: options.comment === true, comments: [], - DEPRECATED__createDefaultProgram: - // eslint-disable-next-line deprecation/deprecation -- will be cleaned up with the next major - options.DEPRECATED__createDefaultProgram === true, debugLevel: options.debugLevel === true ? new Set(['typescript-eslint']) diff --git a/packages/typescript-estree/src/parseSettings/index.ts b/packages/typescript-estree/src/parseSettings/index.ts index 1df275901066..65e197ca70af 100644 --- a/packages/typescript-estree/src/parseSettings/index.ts +++ b/packages/typescript-estree/src/parseSettings/index.ts @@ -47,13 +47,6 @@ export interface MutableParseSettings { */ comments: TSESTree.Comment[]; - /** - * @deprecated - * This is a legacy option that comes with severe performance penalties. - * Please do not use it. - */ - DEPRECATED__createDefaultProgram: boolean; - /** * Which debug areas should be logged. */ diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts index 5df5b5b0e271..4ca27d0bc639 100644 --- a/packages/typescript-estree/src/parser-options.ts +++ b/packages/typescript-estree/src/parser-options.ts @@ -192,12 +192,6 @@ interface ParseAndGenerateServicesOptions extends ParseOptions { */ programs?: ts.Program[] | null; - /** - * @deprecated - this flag will be removed in the next major. - * Do not rely on the behavior provided by this flag. - */ - DEPRECATED__createDefaultProgram?: boolean; - /** * ESLint (and therefore typescript-eslint) is used in both "single run"/one-time contexts, * such as an ESLint CLI invocation, and long-running sessions (such as continuous feedback diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index ffa0c4212295..4c4b7f61a848 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -3,7 +3,6 @@ import type * as ts from 'typescript'; import { astConverter } from './ast-converter'; import { convertError } from './convert'; -import { createDefaultProgram } from './create-program/createDefaultProgram'; import { createIsolatedProgram } from './create-program/createIsolatedProgram'; import { createProjectProgram } from './create-program/createProjectProgram'; import { @@ -76,24 +75,10 @@ function getProgramAndAST( return createNoProgram(parseSettings); } - const fromProjectProgram = createProjectProgram( + return createProjectProgram( parseSettings, getWatchProgramsForProjects(parseSettings), ); - if (fromProjectProgram) { - return fromProjectProgram; - } - - // eslint-disable-next-line deprecation/deprecation -- will be cleaned up with the next major - if (parseSettings.DEPRECATED__createDefaultProgram) { - // eslint-disable-next-line deprecation/deprecation -- will be cleaned up with the next major - const fromDefaultProgram = createDefaultProgram(parseSettings); - if (fromDefaultProgram) { - return fromDefaultProgram; - } - } - - return createIsolatedProgram(parseSettings); } // eslint-disable-next-line @typescript-eslint/no-empty-interface diff --git a/packages/typescript-estree/tests/lib/semanticInfo.test.ts b/packages/typescript-estree/tests/lib/semanticInfo.test.ts index f5f78934a880..eac23a5deeab 100644 --- a/packages/typescript-estree/tests/lib/semanticInfo.test.ts +++ b/packages/typescript-estree/tests/lib/semanticInfo.test.ts @@ -302,15 +302,6 @@ describe('semanticInfo', () => { }); } - it('default program produced with option', () => { - const parseResult = parseCodeAndGenerateServices('var foo = 5;', { - ...createOptions(''), - DEPRECATED__createDefaultProgram: true, - }); - - expectToHaveParserServices(parseResult.services); - }); - it('empty programs array should throw', () => { const fileName = path.resolve(FIXTURES_DIR, 'isolated-file.src.ts'); const badConfig = createOptions(fileName); diff --git a/packages/website/src/components/linter/config.ts b/packages/website/src/components/linter/config.ts index 8262487369c1..fea3cf897b16 100644 --- a/packages/website/src/components/linter/config.ts +++ b/packages/website/src/components/linter/config.ts @@ -10,7 +10,6 @@ export const defaultParseSettings: ParseSettings = { comment: true, comments: [], debugLevel: new Set(), - DEPRECATED__createDefaultProgram: false, errorOnTypeScriptSyntacticAndSemanticIssues: false, errorOnUnknownASTType: false, EXPERIMENTAL_projectService: undefined, From 5c740df0826b06af57724b08daeb8b0f4d82bfef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josh=20Goldberg=20=E2=9C=A8?= Date: Mon, 15 Apr 2024 10:32:56 -0400 Subject: [PATCH 2/2] Update packages/typescript-estree/src/create-program/createProjectProgram.ts Co-authored-by: Brad Zacher --- .../src/create-program/createProjectProgram.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/typescript-estree/src/create-program/createProjectProgram.ts b/packages/typescript-estree/src/create-program/createProjectProgram.ts index 4b8955c28c41..280e48daff2e 100644 --- a/packages/typescript-estree/src/create-program/createProjectProgram.ts +++ b/packages/typescript-estree/src/create-program/createProjectProgram.ts @@ -35,8 +35,7 @@ function createProjectProgram( getAstFromProgram(currentProgram, parseSettings.filePath), ); - // The file was either matched within the tsconfig, or we allow creating a default program - // eslint-disable-next-line deprecation/deprecation -- will be cleaned up with the next major + // The file was matched within the tsconfig if (astAndProgram) { return astAndProgram; }