Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
docs: flesh out tips for typed linting and .eslintrc.cjs#6919
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
7f18904
0e23a30
87117c7
6c35975
3de2d52
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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. @Jutanium would love your input on this if you have time 😇 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -30,21 +30,67 @@ If you don't find an existing extension rule, or the extension rule doesn't work | ||
## 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. | ||
### Fixing the Error | ||
<!-- prettier-ignore-start --> | ||
JoshuaKGoldberg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
- 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.mdx): | ||
- 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: | ||
<details> | ||
<summary> | ||
A popular setup is to remove all rules requiring type information from the top-level configuration | ||
and only apply them to TypeScript files via an override. | ||
</summary> | ||
```js title=".eslintrc.cjs" | ||
module.exports = { | ||
// ... the rest of your config ... | ||
overrides: [ | ||
{ | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended-requiring-type-checking', | ||
], | ||
files: ['./**/*.{ts,tsx}'], | ||
}, | ||
], | ||
}; | ||
``` | ||
</details> | ||
<details> | ||
JoshuaKGoldberg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
<summary> | ||
Alternatively, in our <a href="/blog/announcing-typescript-eslint-v6-beta">version v6</a>, you can use our{' '} | ||
<a href="https://v6--typescript-eslint.netlify.app/linting/configs#disable-type-checked"><code>disable-type-checked</code> config</a> to disable type checking for just that type of file. | ||
</summary> | ||
```js title=".eslintrc.cjs" | ||
module.exports = { | ||
// ... the rest of your config ... | ||
overrides: [ | ||
{ | ||
extends: ['plugin:@typescript-eslint/disable-type-checked'], | ||
files: ['./**/*.js'], | ||
}, | ||
], | ||
}; | ||
``` | ||
To disable type checking for files manually, set `parserOptions: { project: null }` to an override for the files you wish to exclude. Note that `{ project: undefined }` will not work, and you'll also need to disable any rules or rule options that require type checking. | ||
</details> | ||
- If you **do** want to lint the file with [type-aware linting](./Typed_Linting.mdx): | ||
- 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 the file is a `.cjs`, `.js`, or `.mjs` file, make sure [`allowJs`](https://www.typescriptlang.org/tsconfig#allowJs) is enabled. | ||
- 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) | ||
<!-- prettier-ignore-end --> | ||
### More Details | ||
This error may appear from the combination of two things: | ||