From 945aa58a67a400a65a647665ff34350d83374272 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Fri, 2 Feb 2024 10:55:28 +1030 Subject: [PATCH 1/4] feat: allow false for parserOptons.project --- docs/packages/Parser.mdx | 10 +++++++--- docs/packages/TypeScript_ESTree.mdx | 4 +++- packages/types/src/parser-options.ts | 2 +- .../src/parseSettings/getProjectConfigFiles.ts | 7 ++++--- packages/typescript-estree/src/parser-options.ts | 4 +++- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/packages/Parser.mdx b/docs/packages/Parser.mdx index 5d5860493103..35f61e0d8a69 100644 --- a/docs/packages/Parser.mdx +++ b/docs/packages/Parser.mdx @@ -45,8 +45,8 @@ interface ParserOptions { jsxFragmentName?: string | null; jsxPragma?: string | null; lib?: string[]; - programs?: import('typescript').Program; - project?: string | string[] | true; + programs?: import('typescript').Program[]; + project?: string | string[] | true | boolean | null; projectFolderIgnoreList?: string[]; tsconfigRootDir?: string; warnOnUnsupportedTypeScriptVersion?: boolean; @@ -212,13 +212,17 @@ This option allows you to provide a path to your project's `tsconfig.json`. **Th // array of paths and/or glob patterns project: ['./packages/**/tsconfig.json', './separate-package/tsconfig.json']; + + // ways to disable type-aware linting (useful for overrides configs) + project: false; + project: null; ``` - If `true`, each source file's parse will find the nearest `tsconfig.json` file to that source file. - This is done by checking that source file's directory tree for the nearest `tsconfig.json`. -- 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. - Note that using wide globs `**` in your `parserOptions.project` may cause performance implications. Instead of globs that use `**` to recursively check all folders, prefer paths that use a single `*` at a time. For more info see [#2611](https://github.com/typescript-eslint/typescript-eslint/issues/2611). diff --git a/docs/packages/TypeScript_ESTree.mdx b/docs/packages/TypeScript_ESTree.mdx index 27122374bd18..a90c98458fa2 100644 --- a/docs/packages/TypeScript_ESTree.mdx +++ b/docs/packages/TypeScript_ESTree.mdx @@ -209,8 +209,10 @@ interface ParseAndGenerateServicesOptions extends ParseOptions { * Absolute (or relative to `tsconfigRootDir`) paths to the tsconfig(s), * or `true` to find the nearest tsconfig.json to the file. * If this is provided, type information will be returned. + * + * If set to `false`, `null` or `undefined` type information will not be returned. */ - project?: string | string[] | true; + project?: string[] | string | boolean | null; /** * If you provide a glob (or globs) to the project option, you can use this option to ignore certain folders from diff --git a/packages/types/src/parser-options.ts b/packages/types/src/parser-options.ts index 885645f4bbae..12f5e20144da 100644 --- a/packages/types/src/parser-options.ts +++ b/packages/types/src/parser-options.ts @@ -63,7 +63,7 @@ interface ParserOptions { jsDocParsingMode?: JSDocParsingMode; loc?: boolean; programs?: Program | null; - project?: string[] | string | true | null; + project?: string[] | string | boolean | null; projectFolderIgnoreList?: (RegExp | string)[]; range?: boolean; sourceType?: SourceType; diff --git a/packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts b/packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts index 64af27985f0e..1765f2cb1250 100644 --- a/packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts +++ b/packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts @@ -2,7 +2,8 @@ import debug from 'debug'; import * as fs from 'fs'; import * as path from 'path'; -import type { ParseSettings } from '.'; +import type { TSESTreeOptions } from '../parser-options'; +import type { ParseSettings } from './index'; const log = debug('typescript-eslint:typescript-estree:getProjectConfigFiles'); @@ -20,10 +21,10 @@ export function getProjectConfigFiles( ParseSettings, 'filePath' | 'tsconfigMatchCache' | 'tsconfigRootDir' >, - project: string[] | string | true | null | undefined, + project: TSESTreeOptions['project'], ): string[] | null { if (project !== true) { - if (project == null) { + if (project == null || project === false) { return null; } if (Array.isArray(project)) { diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts index e86be6d50996..208de53b55cc 100644 --- a/packages/typescript-estree/src/parser-options.ts +++ b/packages/typescript-estree/src/parser-options.ts @@ -166,8 +166,10 @@ interface ParseAndGenerateServicesOptions extends ParseOptions { * Absolute (or relative to `tsconfigRootDir`) paths to the tsconfig(s), * or `true` to find the nearest tsconfig.json to the file. * If this is provided, type information will be returned. + * + * If set to `false`, `null` or `undefined` type information will not be returned. */ - project?: string[] | string | true | null; + project?: string[] | string | boolean | null; /** * If you provide a glob (or globs) to the project option, you can use this option to ignore certain folders from From 1be8375f72121faaf1efb61275c293d784532b4d Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Sat, 3 Feb 2024 11:48:42 +1100 Subject: [PATCH 2/4] Update docs/packages/Parser.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Josh Goldberg ✨ --- docs/packages/Parser.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/packages/Parser.mdx b/docs/packages/Parser.mdx index 35f61e0d8a69..07dc36442fe7 100644 --- a/docs/packages/Parser.mdx +++ b/docs/packages/Parser.mdx @@ -46,7 +46,7 @@ interface ParserOptions { jsxPragma?: string | null; lib?: string[]; programs?: import('typescript').Program[]; - project?: string | string[] | true | boolean | null; + project?: string | string[] | boolean | null; projectFolderIgnoreList?: string[]; tsconfigRootDir?: string; warnOnUnsupportedTypeScriptVersion?: boolean; From 7897beccfd2f74bd2e42b0963d5ba8d598bd159a Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Sat, 3 Feb 2024 11:48:55 +1100 Subject: [PATCH 3/4] Update docs/packages/TypeScript_ESTree.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Josh Goldberg ✨ --- docs/packages/TypeScript_ESTree.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/packages/TypeScript_ESTree.mdx b/docs/packages/TypeScript_ESTree.mdx index a90c98458fa2..f589cb8f6605 100644 --- a/docs/packages/TypeScript_ESTree.mdx +++ b/docs/packages/TypeScript_ESTree.mdx @@ -210,7 +210,7 @@ interface ParseAndGenerateServicesOptions extends ParseOptions { * or `true` to find the nearest tsconfig.json to the file. * If this is provided, type information will be returned. * - * If set to `false`, `null` or `undefined` type information will not be returned. + * If set to `false`, `null`, or `undefined`, type information will not be returned. */ project?: string[] | string | boolean | null; From 639b2fad3110571da5580a4a770a22f0f75099d0 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Sun, 4 Feb 2024 13:08:11 +1100 Subject: [PATCH 4/4] add test --- .../tests/lib/getProjectConfigFiles.test.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/typescript-estree/tests/lib/getProjectConfigFiles.test.ts b/packages/typescript-estree/tests/lib/getProjectConfigFiles.test.ts index 1ca184e44102..05a605138b69 100644 --- a/packages/typescript-estree/tests/lib/getProjectConfigFiles.test.ts +++ b/packages/typescript-estree/tests/lib/getProjectConfigFiles.test.ts @@ -38,12 +38,14 @@ describe('getProjectConfigFiles', () => { expect(actual).toEqual(project); }); - it('returns the project when given as undefined', () => { - const project = undefined; - - const actual = getProjectConfigFiles(parseSettings, project); - - expect(actual).toBeNull(); + describe('it does not enable type-aware linting when given as', () => { + for (const project of [undefined, null, false]) { + it(`${project}`, () => { + const actual = getProjectConfigFiles(parseSettings, project); + + expect(actual).toBeNull(); + }); + } }); describe('when caching hits', () => {