8000 feat: allow `parserOptions.project: false` (#8339) · danvk/typescript-eslint@5d00bae · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d00bae

Browse files
bradzacherdanvk
authored andcommitted
feat: allow parserOptions.project: false (typescript-eslint#8339)
1 parent 14d86d1 commit 5d00bae

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

docs/packages/Parser.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ interface ParserOptions {
4545
jsxFragmentName?: string | null;
4646
jsxPragma?: string | null;
4747
lib?: string[];
48-
programs?: import('typescript').Program;
49-
project?: string | string[] | true;
48+
programs?: import('typescript').Program[];
49+
project?: string | string[] | boolean | null;
5050
projectFolderIgnoreList?: string[];
5151
tsconfigRootDir?: string;
5252
warnOnUnsupportedTypeScriptVersion?: boolean;
@@ -212,13 +212,17 @@ This option allows you to provide a path to your project's `tsconfig.json`. **Th
212212

213213
// array of paths and/or glob patterns
214214
project: ['./packages/**/tsconfig.json', './separate-package/tsconfig.json'];
215+
216+
// ways to disable type-aware linting (useful for overrides configs)
217+
project: false;
218+
project: null;
215219
```
216220

217221
- If `true`, each source file's parse will find the nearest `tsconfig.json` file to that source file.
218222

219223
- This is done by checking that source file's directory tree for the nearest `tsconfig.json`.
220224

221-
- 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.
225+
- 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.
222226

223227
- 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).
224228

docs/packages/TypeScript_ESTree.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ interface ParseAndGenerateServicesOptions extends ParseOptions {
209209
* Absolute (or relative to `tsconfigRootDir`) paths to the tsconfig(s),
210210
* or `true` to find the nearest tsconfig.json to the file.
211211
* If this is provided, type information will be returned.
212+
*
213+
* If set to `false`, `null`, or `undefined`, type information will not be returned.
212214
*/
213-
project?: string | string[] | true;
215+
project?: string[] | string | boolean | null;
214216

215217
/**
216218
* If you provide a glob (or globs) to the project option, you can use this option to ignore certain folders from

packages/types/src/parser-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ interface ParserOptions {
6363
jsDocParsingMode?: JSDocParsingMode;
6464
loc?: boolean;
6565
programs?: Program | null;
66-
project?: string[] | string | true | null;
66+
project?: string[] | string | boolean | null;
6767
projectFolderIgnoreList?: (RegExp | string)[];
6868
range?: boolean;
6969
sourceType?: SourceType;

packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import debug from 'debug';
22
import * as fs from 'fs';
33
import * as path from 'path';
44

5-
import type { ParseSettings } from '.';
5+
import type { TSESTreeOptions } from '../parser-options';
6+
import type { ParseSettings } from './index';
67

78
const log = debug('typescript-eslint:typescript-estree:getProjectConfigFiles');
89

@@ -20,10 +21,10 @@ export function getProjectConfigFiles(
2021
ParseSettings,
2122
'filePath' | 'tsconfigMatchCache' | 'tsconfigRootDir'
2223
>,
23-
project: string[] | string | true | null | undefined,
24+
project: TSESTreeOptions['project'],
2425
): string[] | null {
2526
if (project !== true) {
26-
if (project == null) {
27+
if (project == null || project === false) {
2728
return null;
2829
}
2930
if (Array.isArray(project)) {

packages/typescript-estree/src/parser-options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ interface ParseAndGenerateServicesOptions extends ParseOptions {
166166
* Absolute (or relative to `tsconfigRootDir`) paths to the tsconfig(s),
167167
* or `true` to find the nearest tsconfig.json to the file.
168168
* If this is provided, type information will be returned.
169+
*
170+
* If set to `false`, `null` or `undefined` type information will not be returned.
169171
*/
170-
project?: string[] | string | true | null;
172+
project?: string[] | string | boolean | null;
171173

172174
/**
173175
* If you provide a glob (or globs) to the project option, you can use this option to ignore certain folders from

packages/typescript-estree/tests/lib/getProjectConfigFiles.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ describe('getProjectConfigFiles', () => {
3838
expect(actual).toEqual(project);
3939
});
4040

41-
it('returns the project when given as undefined', () => {
42-
const project = undefined;
43-
44-
const actual = getProjectConfigFiles(parseSettings, project);
45-
46-
expect(actual).toBeNull();
41+
describe('it does not enable type-aware linting when given as', () => {
42+
for (const project of [undefined, null, false]) {
43+
it(`${project}`, () => {
44+
const actual = getProjectConfigFiles(parseSettings, project);
45+
46+
expect(actual).toBeNull();
47+
});
48+
}
4749
});
4850

4951
describe('when caching hits', () => {

0 commit comments

Comments
 (0)
0