Skip to content
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

feat(typescript-estree): deprecate createDefaultProgram #5890

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/parser/README.md
Expand Up @@ -168,7 +168,7 @@ This option allows you to provide a path to your project's `tsconfig.json`. **Th

- 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:
- Note that if this setting is specified, 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:

```jsonc
{
Expand Down Expand Up @@ -217,18 +217,12 @@ Default `true`.

This option allows you to toggle the warning that the parser will give you if you use a version of TypeScript which is not explicitly supported

### `parserOptions.createDefaultProgram`

Default `false`.

This option allows you to request that when the `project` setting is specified, files will be allowed when not included in the projects defined by the provided `tsconfig.json` files. **Using this option will incur significant performance costs. This option is primarily included for backwards-compatibility.** See the **`project`** section above for more information.

### `parserOptions.programs`

Default `undefined`.

This option allows you to programmatically provide an array of one or more instances of a TypeScript Program object that will provide type information to rules.
This will override any programs that would have been computed from `parserOptions.project` or `parserOptions.createDefaultProgram`.
This will override any programs that would have been computed from `parserOptions.project`.
All linted files must be part of the provided program(s).

### `parserOptions.moduleResolver`
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript-estree/README.md
Expand Up @@ -207,6 +207,7 @@ interface ParseAndGenerateServicesOptions extends ParseOptions {
programs?: Program[];

/**
* @deprecated
***************************************************************************************
* IT IS RECOMMENDED THAT YOU DO NOT USE THIS OPTION, AS IT CAUSES PERFORMANCE ISSUES. *
***************************************************************************************
Expand All @@ -215,7 +216,7 @@ interface ParseAndGenerateServicesOptions extends ParseOptions {
* This means that if the parser encounters a file not included in any of the provided `project`s,
* it will not error, but will instead parse the file and its dependencies in a new program.
*/
createDefaultProgram?: boolean;
deprecated__createDefaultProgram?: boolean;
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved

/**
* ESLint (and therefore typescript-eslint) is used in both "single run"/one-time contexts,
Expand Down
Expand Up @@ -14,6 +14,9 @@ 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,
Expand Down Expand Up @@ -66,4 +69,5 @@ function createDefaultProgram(
return ast && { ast, program };
}

// eslint-disable-next-line deprecation/deprecation
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
export { createDefaultProgram };
Expand Up @@ -36,7 +36,7 @@ function createProjectProgram(
);

// The file was either matched within the tsconfig, or we allow creating a default program
if (astAndProgram || parseSettings.createDefaultProgram) {
if (astAndProgram || parseSettings.deprecated__createDefaultProgram) {
return astAndProgram;
}

Expand Down
Expand Up @@ -28,7 +28,8 @@ export function createParseSettings(
code: enforceString(code),
comment: options.comment === true,
comments: [],
createDefaultProgram: options.createDefaultProgram === true,
deprecated__createDefaultProgram:
options.deprecated__createDefaultProgram === true,
debugLevel:
options.debugLevel === true
? new Set(['typescript-eslint'])
Expand Down
5 changes: 4 additions & 1 deletion packages/typescript-estree/src/parseSettings/index.ts
Expand Up @@ -26,8 +26,11 @@ export interface MutableParseSettings {

/**
* Whether to create a TypeScript program if one is not provided.
* @deprecated
* This is a legacy option that comes with severe performance penalties.
* Please do not use it.
*/
createDefaultProgram: boolean;
deprecated__createDefaultProgram: boolean;

/**
* Which debug areas should be logged.
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript-estree/src/parser-options.ts
Expand Up @@ -144,6 +144,7 @@ interface ParseAndGenerateServicesOptions extends ParseOptions {
programs?: ts.Program[];

/**
* @deprecated
***************************************************************************************
* IT IS RECOMMENDED THAT YOU DO NOT USE THIS OPTION, AS IT CAUSES PERFORMANCE ISSUES. *
***************************************************************************************
Expand All @@ -152,7 +153,7 @@ interface ParseAndGenerateServicesOptions extends ParseOptions {
* This means that if the parser encounters a file not included in any of the provided `project`s,
* it will not error, but will instead parse the file and its dependencies in a new program.
*/
createDefaultProgram?: boolean;
deprecated__createDefaultProgram?: boolean;

/**
* ESLint (and therefore typescript-eslint) is used in both "single run"/one-time contexts,
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript-estree/src/parser.ts
Expand Up @@ -44,7 +44,8 @@ function getProgramAndAST(
useProvidedPrograms(parseSettings.programs, parseSettings)) ||
(shouldProvideParserServices && createProjectProgram(parseSettings)) ||
(shouldProvideParserServices &&
parseSettings.createDefaultProgram &&
// eslint-disable-next-line deprecation/deprecation
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
parseSettings.deprecated__createDefaultProgram &&
createDefaultProgram(parseSettings)) ||
createIsolatedProgram(parseSettings)
);
Expand Down
10 changes: 5 additions & 5 deletions packages/typescript-estree/tests/lib/parse.test.ts
Expand Up @@ -773,10 +773,10 @@ describe('parseAndGenerateServices', () => {
tsconfigRootDir: PROJECT_DIR,
filePath: resolve(PROJECT_DIR, 'file.ts'),
};
const withDefaultProgramConfig: TSESTreeOptions = {
const withDeprecatedDefaultProgramConfig: TSESTreeOptions = {
...config,
project: './tsconfig.defaultProgram.json',
createDefaultProgram: true,
deprecated__createDefaultProgram: true,
};

describe('when file is in the project', () => {
Expand Down Expand Up @@ -818,11 +818,11 @@ describe('parseAndGenerateServices', () => {
});
});

describe('when file is not in the project and createDefaultProgram=true', () => {
describe('when file is not in the project and deprecated__createDefaultProgram=true', () => {
it('returns error because __PLACEHOLDER__ can not be resolved', () => {
expect(
parser
.parseAndGenerateServices(code, withDefaultProgramConfig)
.parseAndGenerateServices(code, withDeprecatedDefaultProgramConfig)
.services.program.getSemanticDiagnostics(),
).toHaveProperty(
[0, 'messageText'],
Expand All @@ -834,7 +834,7 @@ describe('parseAndGenerateServices', () => {
expect(
parser
.parseAndGenerateServices(code, {
...withDefaultProgramConfig,
...withDeprecatedDefaultProgramConfig,
moduleResolver: resolve(PROJECT_DIR, './moduleResolver.js'),
})
.services.program.getSemanticDiagnostics(),
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-estree/tests/lib/semanticInfo.test.ts
Expand Up @@ -287,7 +287,7 @@ describe('semanticInfo', () => {
it('default program produced with option', () => {
const parseResult = parseCodeAndGenerateServices('var foo = 5;', {
...createOptions('<input>'),
createDefaultProgram: true,
deprecated__createDefaultProgram: true,
});

expect(parseResult.services.program).toBeDefined();
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/linter/config.ts
Expand Up @@ -4,7 +4,7 @@ export const parseSettings: ParseSettings = {
code: '',
comment: true,
comments: [],
createDefaultProgram: false,
deprecated__createDefaultProgram: false,
debugLevel: new Set(),
errorOnUnknownASTType: false,
extraFileExtensions: [],
Expand Down