-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(typescript-estree): clarify docs and error for program project without matching TSConfig #5762
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 14 commits into
typescript-eslint:main
from
JoshuaKGoldberg:improve-program-no-tsconfig-include-error
Oct 24, 2022
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4f6b622
feat(typescript-estree): clarify docs and error for program project w…
JoshuaKGoldberg f3c7b0d
lil cspell nit
JoshuaKGoldberg acb9df1
Update docs/linting/TROUBLESHOOTING.md
JoshuaKGoldberg 1a76e12
Merge branch 'main' into improve-program-no-tsconfig-include-error
JoshuaKGoldberg e94a406
Apply suggestions from code review
JoshuaKGoldberg fae5eb3
Resolved a few docs comments
JoshuaKGoldberg cba66e7
A few test fixes
JoshuaKGoldberg a696b04
Remove period
JoshuaKGoldberg 7d6c877
Merge branch 'main' into improve-program-no-tsconfig-include-error
JoshuaKGoldberg b918d48
Apply suggestions from code review
JoshuaKGoldberg 674ebe9
Link to FAQ article
JoshuaKGoldberg 606a4b3
Reordered docs, and updated tests
JoshuaKGoldberg def07d6
Merge branch 'main' into improve-program-no-tsconfig-include-error
JoshuaKGoldberg 73e875f
Merge branch 'main' into improve-program-no-tsconfig-include-error
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,48 @@ 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](https://typescript-eslint.io/rules/#extension-rules) **_before_** filing an issue. | ||
|
||
## I get errors telling me "The file must be included in at least one of the projects provided" | ||
## I get errors telling me "ESLint was configured to run ... However, that TSConfig does not / none of those TSConfigs include this file" | ||
|
||
### Fixing the Error | ||
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. I split this section into these two h3s. Re-reading the un-split explanation felt like a tl;dr. My instinct is users just want to know how to fix this ASAP. |
||
|
||
- If you **do not** want to lint the file: | ||
- Use [one of the options ESLint offers](https://eslint.org/docs/latest/user-guide/configuring/ignoring-code) to ignore files, namely a `.eslintignore` file, or `ignorePatterns` config. | ||
- If you **do** want to lint the file: | ||
- If you **do not** want to lint the file with [type-aware linting](./TYPED_LINTING.md): | ||
- Use [ESLint's `overrides` configuration](https://eslint.org/docs/latest/user-guide/configuring/configuration-files#configuration-based-on-glob-patterns) to configure the file to not be parsed with type information. | ||
- A popular setup is to omit the above additions from top-level configuration and only apply them to TypeScript files via an override. | ||
- Alternatively, you can add `parserOptions: { project: null }` to an override for the files you wish to exclude. Note that `{ project: undefined }` will not work. | ||
- If you **do** want to lint the file with [type-aware linting](./TYPED_LINTING.md): | ||
- Check the `include` option of each of the tsconfigs that you provide to `parserOptions.project` - you must ensure that all files match an `include` glob, or else our tooling will not be able to find it. | ||
- If your file shouldn't be a part of one of your existing tsconfigs (for example, it is a script/tool local to the repo), then consider creating a new tsconfig (we advise calling it `tsconfig.eslint.json`) in your project root which lists this file in its `include`. For an example of this, you can check out the configuration we use in this repo: | ||
- [`tsconfig.eslint.json`](https://github.com/typescript-eslint/typescript-eslint/blob/main/tsconfig.eslint.json) | ||
- [`.eslintrc.js`](https://github.com/typescript-eslint/typescript-eslint/blob/main/.eslintrc.js) | ||
|
||
### More Details | ||
|
||
This error may appear from the combination of two things: | ||
|
||
- The ESLint configuration for the source file specifies at least one TSConfig file in `parserOptions.project` | ||
- None of those TSConfig files includes the source file being linted | ||
JoshuaKGoldberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Note that files with the same name and different extension may not be recognized by TypeScript: see [`parserOptions.project` docs](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/parser#parseroptionsproject) | ||
|
||
This error means that the file that's being linted is not included in any of the TSConfig files you provided us. | ||
This happens when users have test files, config files, or similar that are not included. | ||
When TSConfig files are specified for parsing a source file, `@typescript-eslint/parser` will use the first TSConfig that is able to include that source file (per [aka.ms/tsconfig#include](https://www.typescriptlang.org/tsconfig#include)) to generate type information. | ||
However, if no specified TSConfig includes the source file, the parser won't be able to generate type information. | ||
|
||
This error most commonly happens on config files or similar that are not included in their project TSConfig(s). | ||
For example, many projects have files like: | ||
|
||
- An `.eslintrc.cjs` with `parserOptions.project: ["./tsconfig.json"]` | ||
- A `tsconfig.json` with `include: ["src"]` | ||
|
||
In that case, viewing the `.eslintrc.cjs` in an IDE with the ESLint extension will show the error notice that the file couldn't be linted because it isn't included in `tsconfig.json`. | ||
|
||
See our docs on [type aware linting](./TYPED_LINTING.md) for more information. | ||
|
||
## I get errors telling me "The file must be included in at least one of the projects provided" | ||
|
||
See our docs on [type aware linting](./TYPED_LINTING.md#i-get-errors-telling-me-the-file-must-be-included-in-at-least-one-of-the-projects-provided) for solutions. | ||
You're using an outdated version of `@typescript-eslint/parser`. | ||
Update to the latest version to see a more informative version of this error message, explained [above](#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file). | ||
|
||
## I use a framework (like Vue) that requires custom file extensions, and I get errors like "You should add `parserOptions.extraFileExtensions` to your config" | ||
|
||
|
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
1 change: 1 addition & 0 deletions
1
packages/typescript-estree/tests/fixtures/invalidFileErrors/tsconfig.extra.json
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 @@ | ||
{} |
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.
Uh oh!
There was an error while loading. Please reload this page.