-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(typescript-estree): add maximumDefaultProjectFileMatchCount and wide allowDefaultProjectForFiles glob restrictions #8925
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
JoshuaKGoldberg
merged 5 commits into
typescript-eslint:main
from
JoshuaKGoldberg:maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING
Apr 25, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3f12035
feat(typescript-estree): add maximumDefaultProjectFileMatchCount
JoshuaKGoldberg 662dffd
Also disallow '*'
JoshuaKGoldberg 1615505
lil touchup for the asterisk
JoshuaKGoldberg ebf15a4
Spelling and Windows normalization
JoshuaKGoldberg d00856e
Also reset new cache in persistentParse.test.ts
JoshuaKGoldberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,40 @@ If you don't find an existing extension rule, or the extension rule doesn't work | |
> We release a new version our tooling every week. | ||
> _Please_ ensure that you [check our the latest list of "extension" rules](/rules/#extension-rules) **_before_** filing an issue. | ||
|
||
<HiddenHeading id="allowdefaultprojectforfiles-glob-too-wide" /> | ||
|
||
## I get errors telling me "Having many files run with the default project is known to cause performance issues and slow down linting." | ||
|
||
These errors are caused by using the [`EXPERIMENTAL_useProjectService`](../packages/Parser.mdx#experimental_useprojectservice) `allowDefaultProjectForFiles` with an excessively wide glob. | ||
`allowDefaultProjectForFiles` causes a new TypeScript "program" to be built for each "out of project" file it includes, which incurs a performance overhead for each file. | ||
|
||
To resolve this error, narrow the glob(s) used for `allowDefaultProjectForFiles` to include fewer files. | ||
For example: | ||
|
||
```diff title="eslint.config.js" | ||
parserOptions: { | ||
EXPERIMENTAL_useProjectService: { | ||
allowDefaultProjectForFiles: [ | ||
- "**/*.js", | ||
+ "./*.js" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
You may also need to include more files in your `tsconfig.json`. | ||
For example: | ||
|
||
```diff title="tsconfig.json" | ||
"include": [ | ||
"src", | ||
+ "*.js" | ||
] | ||
``` | ||
|
||
If you cannot do this, please [file an issue on typescript-eslint's typescript-estree package](https://github.com/typescript-eslint/typescript-eslint/issues/new?assignees=&labels=enhancement%2Ctriage&projects=&template=07-enhancement-other.yaml&title=Enhancement%3A+%3Ca+short+description+of+my+proposal%3E) telling us your use case and why you need more out-of-project files linted. | ||
Be sure to include a minimal reproduction we can work with to understand your use case! | ||
|
||
## I get errors telling me "ESLint was configured to run ... However, that TSConfig does not / none of those TSConfigs include this file" | ||
|
||
These errors are caused by an ESLint config requesting type information be generated for a file that isn't included in the TypeScript configuration. | ||
|
@@ -499,6 +533,6 @@ If you think you're having issues with performance, see our [Performance Trouble | |
|
||
## Are TypeScript project references supported? | ||
|
||
No, TypeScript project references are not yet supported. | ||
Yes, but only with [`EXPERIMENTAL_useProjectService`](../packages/Parser.mdx#experimental_useprojectservice). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aside: we'll definitely want more explanation here 😄 but quickly noted this in the meantime. Once this & a few more v8 milestone PRs are in, #7350 tracks a full blog post / explainer / revamp. |
||
|
||
See [issue #2094 discussing project references](https://github.com/typescript-eslint/typescript-eslint/issues/2094) for more details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/typescript-estree/src/create-program/validateDefaultProjectForFilesGlob.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { ProjectServiceOptions } from '../parser-options'; | ||
|
||
export const DEFAULT_PROJECT_FILES_ERROR_EXPLANATION = ` | ||
|
||
Having many files run with the default project is known to cause performance issues and slow down linting. | ||
|
||
See https://typescript-eslint.io/troubleshooting/#allowdefaultprojectforfiles-glob-too-wide | ||
`; | ||
|
||
export function validateDefaultProjectForFilesGlob( | ||
options: ProjectServiceOptions, | ||
): void { | ||
if (!options.allowDefaultProjectForFiles?.length) { | ||
return; | ||
} | ||
|
||
for (const glob of options.allowDefaultProjectForFiles) { | ||
if (glob === '*') { | ||
throw new Error( | ||
`allowDefaultProjectForFiles contains the overly wide '*'.${DEFAULT_PROJECT_FILES_ERROR_EXPLANATION}`, | ||
); | ||
} | ||
if (glob.includes('**')) { | ||
throw new Error( | ||
`allowDefaultProjectForFiles glob '${glob}' contains a disallowed '**'.${DEFAULT_PROJECT_FILES_ERROR_EXPLANATION}`, | ||
); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: filed #8926 to reduce the scale of this kind of huge FAQs list.