Skip to content

feat: allow parserOptions.project: false #8339

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

Merged
merged 5 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions docs/packages/Parser.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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[] | boolean | null;
projectFolderIgnoreList?: string[];
tsconfigRootDir?: string;
warnOnUnsupportedTypeScriptVersion?: boolean;
Expand Down Expand Up @@ -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).

Expand Down
4 changes: 3 additions & 1 deletion docs/packages/TypeScript_ESTree.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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)) {
Expand Down
4 changes: 3 additions & 1 deletion packages/typescript-estree/src/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down