You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/getting-started/Legacy_ESLint_Setup.mdx
+32-2Lines changed: 32 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -84,10 +84,40 @@ ESLint will lint all TypeScript compatible files within the current folder, and
84
84
85
85
## Next Steps
86
86
87
-
We provide a plethora of powerful rules that utilize the power of TypeScript's type information. [Visit _Typed Rules_ for a setup guide](./Typed_Linting.mdx).
88
-
89
87
If you're having problems getting this working, please have a look at our [Troubleshooting & FAQs](../troubleshooting/FAQ.mdx).
90
88
89
+
### Additional Configs
90
+
91
+
We recommend you consider enabling the following two configs:
92
+
93
+
-[`strict`](../users/Shared_Configurations.mdx#strict): a superset of `recommended` that includes more opinionated rules which may also catch bugs.
94
+
-[`stylistic`](../users/Shared_Configurations.mdx#stylistic): additional rules that enforce consistent styling without significantly catching bugs or changing logic.
95
+
96
+
```js title=".eslintrc.cjs"
97
+
/* eslint-env node */
98
+
module.exports= {
99
+
extends: [
100
+
'eslint:recommended',
101
+
// Remove this line
102
+
'plugin:@typescript-eslint/recommended',
103
+
// Added lines start
104
+
'plugin:@typescript-eslint/strict',
105
+
'plugin:@typescript-eslint/stylistic',
106
+
// Added lines end
107
+
],
108
+
parser:'@typescript-eslint/parser',
109
+
plugins: ['@typescript-eslint'],
110
+
root:true,
111
+
};
112
+
```
113
+
114
+
You can read more about these in our [shared configurations docs](../users/Shared_Configurations.mdx).
115
+
116
+
### Typed Linting
117
+
118
+
We also provide a plethora of powerful rules that utilize the power of TypeScript's type information.
119
+
[Visit the next page for a typed rules setup guide](./Typed_Linting.mdx).
120
+
91
121
### Documentation Resources
92
122
93
123
- You can read more about configuring ESLint [in their documentation on configuration](https://eslint.org/docs/user-guide/configuring).
This page is a quick-start for [ESLint's new "flat" config format](https://eslint.org/docs/latest/use/configure/configuration-files-new) to go from zero to linting with our recommended rules on your TypeScript code as quickly as possible.
14
+
11
15
:::note
12
-
This page is a quick-start guide for [ESLint's new "flat" config format](https://eslint.org/docs/latest/use/configure/configuration-files-new) to help you go from zero to linting as quick as possible.
13
16
14
17
- For the same guide but for [ESLint's legacy format](https://eslint.org/docs/latest/use/configure/configuration-files) — see [Legacy ESLint Setup](./Legacy_ESLint_Setup.mdx).
15
18
- For quickstart information on linting with type information — see [Typed Linting](./Typed_Linting.mdx).
16
19
17
20
:::
18
21
19
-
## Quickstart
20
-
21
-
These steps will get you running ESLint with our recommended rules on your TypeScript code as quickly as possible.
22
-
23
22
### Step 1: Installation
24
23
25
24
First, install the required packages for [ESLint](https://eslint.org), [TypeScript](https://typescriptlang.org), and [our tooling](../packages/TypeScript_ESLint.mdx):
@@ -82,18 +81,38 @@ ESLint will lint all TypeScript compatible files within the current folder, and
82
81
-`'@eslint/js'` / `eslint.configs.recommended` turns on [eslint's recommended config](https://www.npmjs.com/package/@eslint/js).
83
82
-`...tseslint.configs.recommended` turns on [our recommended config](../users/Shared_Configurations.mdx#recommended).
84
83
85
-
See [ESLint's Configuration Files docs](https://eslint.org/docs/user-guide/configuring/configuration-files-new) for more details on configuring ESLint.
86
-
87
84
## Next Steps
88
85
89
-
We provide a plethora of powerful rules that utilize the power of TypeScript's type information.
86
+
If you're having problems getting this working, please have a look at our [Troubleshooting & FAQs](../troubleshooting/FAQ.mdx).
90
87
91
-
[Visit the next page for a setup guide](./Typed_Linting.mdx'Visit the next page for a typed rules setup guide').
88
+
### Additional Configs
92
89
93
-
If you're having problems getting this working, please have a look at our [Troubleshooting & FAQs](../troubleshooting/FAQ.mdx).
90
+
We recommend you consider enabling the following two configs:
91
+
92
+
-[`strict`](../users/Shared_Configurations.mdx#strict): a superset of `recommended` that includes more opinionated rules which may also catch bugs.
93
+
-[`stylistic`](../users/Shared_Configurations.mdx#stylistic): additional rules that enforce consistent styling without significantly catching bugs or changing logic.
94
+
95
+
```js title="eslint.config.js"
96
+
exportdefaulttseslint.config(
97
+
eslint.configs.recommended,
98
+
// Remove this line
99
+
...tseslint.configs.recommended,
100
+
// Add this line
101
+
...tseslint.configs.strict,
102
+
// Add this line
103
+
...tseslint.configs.stylistic,
104
+
);
105
+
```
106
+
107
+
You can read more about these in our [shared configurations docs](../users/Shared_Configurations.mdx).
108
+
109
+
### Typed Linting
110
+
111
+
We also provide a plethora of powerful rules that utilize the power of TypeScript's type information.
112
+
[Visit the next page for a typed rules setup guide](./Typed_Linting.mdx).
94
113
95
-
###Documentation Resources
114
+
## Documentation Resources
96
115
97
116
- You can read more about configuring ESLint [in their documentation on configuration](https://eslint.org/docs/user-guide/configuring).
98
117
- You can read more about the rules provided by ESLint [in their documentation on their rules](https://eslint.org/docs/rules/).
99
-
- You can read more about the rules provided by typescript-eslint in [our rules documentation](/rules).
118
+
- You can read more about the rules provided by typescript-eslint in our [rules documentation](/rules).
Copy file name to clipboardExpand all lines: docs/getting-started/Typed_Linting.mdx
+65-15Lines changed: 65 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,9 @@ To tap into TypeScript's additional powers, there are two small changes you need
13
13
<TabsgroupId="eslint-config">
14
14
<TabItemvalue="Flat Config">
15
15
16
+
1. Add `TypeChecked` to the name of any preset configs you're using, namely `recommended`, `strict`, and `stylistic`.
17
+
2. Add `languageOptions.parserOptions` to tell our parser how to find the TSConfig for each source file.
18
+
16
19
```js title="eslint.config.js"
17
20
exportdefaulttseslint.config(
18
21
eslint.configs.recommended,
@@ -39,13 +42,16 @@ For CommonJS modules and/or older versions of Node.js, [use `__dirname` or an al
39
42
40
43
In more detail:
41
44
42
-
-`tseslint.configs.recommendedTypeChecked` is another [recommended configuration](../users/Shared_Configurations.mdx) we provide. This one contains recommended rules that additionally require type information.
43
-
-`parserOption.project` tells our parser how to find the TSConfig for each source file (`true` indicates to find the closest `tsconfig.json` for each source file)
44
-
- If your project is a multi-package monorepo, see [our docs on configuring a monorepo](./typed-linting/Monorepos.mdx).
45
+
-`tseslint.configs.recommendedTypeChecked` is another [shared configuration](../users/Shared_Configurations.mdx) we provide. This one contains recommended rules that additionally require type information.
46
+
-`parserOptions.project: true` indicates to find the closest `tsconfig.json` for each source file (see [Parser#project](../packages/Parser.mdx#project)).
47
+
-`parserOptions.tsconfigRootDir` tells our parser the absolute path of your project's root directory (see [Parser#tsconfigRootDir](../packages/Parser.mdx#tsconfigrootdir)).
45
48
46
49
</TabItem>
47
50
<TabItemvalue="Legacy Config">
48
51
52
+
1. Add `-type-checked` to the name of any preset configs you're using, namely `recommended`, `strict`, and `stylistic`.
53
+
2. Add `parserOptions` to tell our parser how to find the TSConfig for each source file.
54
+
49
55
```js title=".eslintrc.cjs"
50
56
/* eslint-env node */
51
57
module.exports= {
@@ -70,9 +76,8 @@ module.exports = {
70
76
71
77
In more detail:
72
78
73
-
-`plugin:@typescript-eslint/recommended-type-checked` is another [recommended configuration](../users/Shared_Configurations.mdx) we provide. This one contains recommended rules that additionally require type information.
74
-
-`parserOptions.project` tells our parser how to find the TSConfig for each source file (`true` indicates to find the closest `tsconfig.json` for each source file)
75
-
- If your project is a multi-package monorepo, see [our docs on configuring a monorepo](./typed-linting/Monorepos.mdx).
79
+
-`plugin:@typescript-eslint/recommended-type-checked` is another [shared configuration](../users/Shared_Configurations.mdx) we provide. This one contains recommended rules that additionally require type information.
80
+
-`parserOptions.project: true` indicates to find the closest `tsconfig.json` for each source file (see [Parser#project](../packages/Parser.mdx#project)).
76
81
-`parserOptions.tsconfigRootDir` tells our parser the absolute path of your project's root directory (see [Parser#tsconfigRootDir](../packages/Parser.mdx#tsconfigrootdir)).
77
82
78
83
</TabItem>
@@ -86,7 +91,57 @@ See [our TSConfig inclusion FAQ](../troubleshooting/FAQ.mdx#i-get-errors-telling
86
91
With that done, run the same lint command you ran before.
87
92
You may see new rules reporting errors based on type information!
88
93
89
-
## Specifying TSConfigs
94
+
## Shared Configurations
95
+
96
+
If you enabled the [`strict` shared config](../users/Shared_Configurations.mdx#strict) and/or [`stylistic` shared config](../users/Shared_Configurations.mdx#stylistic) in a previous step, be sure to replace them with [`strictTypeChecked`](../users/Shared_Configurations.mdx#strict-type-checked) and [`stylisticTypeChecked`](../users/Shared_Configurations.mdx#stylistic-type-checked) respectively to add their type-checked rules.
You can read more about the rules provided by typescript-eslint in our [rules docs](/rules) and [shared configurations docs](../users/Shared_Configurations.mdx).
141
+
142
+
## FAQs
143
+
144
+
### Can I customize the TSConfig used for typed linting?
90
145
91
146
The `project` option can be turned on with either:
92
147
@@ -134,8 +189,6 @@ See [the `@typescript-eslint/parser` docs for more details](../packages/Parser.m
134
189
If your project is a multi-package monorepo, see [our docs on configuring a monorepo](./typed-linting/Monorepos.mdx).
135
190
:::
136
191
137
-
## FAQs
138
-
139
192
### How can I disable type-aware linting for a subset of files?
140
193
141
194
You can combine ESLint's [overrides](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-based-on-glob-patterns) config in conjunction with our [`disable-type-checked`](../users/Shared_Configurations.mdx#disable-type-checked) config to turn off type-aware linting on specific subsets of files.
@@ -147,6 +200,7 @@ You can combine ESLint's [overrides](https://eslint.org/docs/latest/use/configur
@@ -209,11 +264,6 @@ This means that generally they usually only run a complete lint before a push, o
209
264
210
265
**We strongly recommend you do use type-aware linting**, but the above information is included so that you can make your own, informed decision.
211
266
212
-
### I get errors telling me "The file must be included in at least one of the projects provided"
213
-
214
-
You're using an outdated version of `@typescript-eslint/parser`.
215
-
Update to the latest version to see a more informative version of this error message, explained in our [Troubleshooting and FAQs page](../troubleshooting/FAQ.mdx#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file).
216
-
217
267
## Troubleshooting
218
268
219
269
If you're having problems getting this working, please have a look at our [Troubleshooting and FAQs page](../troubleshooting/FAQ.mdx).
Copy file name to clipboardExpand all lines: docs/packages/Parser.mdx
+43-37Lines changed: 43 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -169,7 +169,7 @@ The identifier that's used for JSX fragment elements (after transpilation).
169
169
If `null`, assumes transpilation will always use a member of the configured `jsxPragma`.
170
170
This should not be a member expression - just the root identifier (i.e. use `"h"` instead of `"h.Fragment"`).
171
171
172
-
If you provide `parserOptions.project`, you do not need to set this, as it will automatically detected from the compiler.
172
+
If you provide `parserOptions.project`, you do not need to set this, as it will be automatically detected from the compiler.
173
173
174
174
### `jsxPragma`
175
175
@@ -180,7 +180,7 @@ If you're using a library other than React (like `preact`), then you should chan
180
180
181
181
This should not be a member expression - just the root identifier (i.e. use `"React"` instead of `"React.createElement"`).
182
182
183
-
If you provide `parserOptions.project`, you do not need to set this, as it will automatically detected from the compiler.
183
+
If you provide `parserOptions.project`, you do not need to set this, as it will be automatically detected from the compiler.
184
184
185
185
### `lib`
186
186
@@ -190,7 +190,7 @@ For valid options, see the [TypeScript compiler options](https://www.typescriptl
190
190
191
191
Specifies the TypeScript `lib`s that are available. This is used by the scope analyser to ensure there are global variables declared for the types exposed by TypeScript.
192
192
193
-
If you provide `parserOptions.project`, you do not need to set this, as it will automatically detected from the compiler.
193
+
If you provide `parserOptions.project`, you do not need to set this, as it will be automatically detected from the compiler.
194
194
195
195
### `programs`
196
196
@@ -206,27 +206,27 @@ All linted files must be part of the provided program(s).
206
206
207
207
> Default `undefined`.
208
208
209
-
This option allows you to provide a path to your project's `tsconfig.json`.**This setting is required if you want to use rules which require type information**. Relative paths are interpreted relative to the current working directory if `tsconfigRootDir` is not set. If you intend on running ESLint from directories other than the project root, you should consider using `tsconfigRootDir`.
209
+
A path to your project's TSConfig.**This setting is required to use [rules which require type information](../getting-started/Typed_Linting.mdx)**.
210
210
211
-
-Accepted values:
211
+
Accepted value types:
212
212
213
-
```js
214
-
// find the tsconfig.json nearest each source file
215
-
project:true,
213
+
```js
214
+
// find the tsconfig.json nearest to each source file
// ways to disable type-aware linting (useful for overrides configs)
227
-
project:false;
228
-
project:null;
229
-
```
226
+
// ways to disable type-aware linting (useful for overrides configs)
227
+
project:false;
228
+
project:null;
229
+
```
230
230
231
231
- If `true`, each source file's parse will find the nearest `tsconfig.json` file to that source file.
232
232
@@ -236,25 +236,31 @@ This option allows you to provide a path to your project's `tsconfig.json`. **Th
236
236
237
237
- 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).
238
238
239
-
- TypeScript will ignore files with duplicate filenames in the same folder (for example, `src/file.ts` and `src/file.js`). TypeScript purposely ignore all but one of the files, only keeping the one file with the highest priority extension (the extension priority order (from highest to lowest) is `.ts`, `.tsx`, `.d.ts`, `.js`, `.jsx`). For more info see #955.
240
-
241
-
- Note that if this setting is specified, you must only lint files that are included in the projects as defined by the provided `tsconfig.json` files. If your existing configuration does not include all of the files you would like to lint, you can create a separate `tsconfig.eslint.json` as follows:
242
-
243
-
```jsonc
244
-
{
245
-
// extend your base config so you don't have to redefine your compilerOptions
246
-
"extends":"./tsconfig.json",
247
-
"include": [
248
-
"src/**/*.ts",
249
-
"test/**/*.ts",
250
-
"typings/**/*.ts",
251
-
// etc
252
-
253
-
// if you have a mixed JS/TS codebase, don't forget to include your JS files
254
-
"src/**/*.js",
255
-
],
256
-
}
257
-
```
239
+
- TypeScript will ignore files with duplicate filenames in the same folder (for example, `src/file.ts` and `src/file.js`). TypeScript purposely ignores all but one of the files, only keeping the one file with the highest priority extension (the extension priority order (from highest to lowest) is `.ts`, `.tsx`, `.d.ts`, `.js`, `.jsx`). For more info see [#955](https://github.com/typescript-eslint/typescript-eslint/issues/955).
240
+
241
+
:::note
242
+
Relative paths are interpreted relative to the current working directory if [`tsconfigRootDir`](#tsconfigrootdir) is not set.
243
+
:::
244
+
245
+
If this setting is specified, you must only lint files that are included in the projects as defined by the provided TSConfig file(s). If your existing configuration does not include all of the files you would like to lint, you can create a separate `tsconfig.eslint.json` as follows:
246
+
247
+
```jsonc
248
+
{
249
+
// extend your base config so you don't have to redefine your compilerOptions
250
+
"extends":"./tsconfig.json",
251
+
"include": [
252
+
"src/**/*.ts",
253
+
"test/**/*.ts",
254
+
"typings/**/*.ts",
255
+
// etc
256
+
257
+
// if you have a mixed JS/TS codebase, don't forget to include your JS files
258
+
"src/**/*.js",
259
+
],
260
+
}
261
+
```
262
+
263
+
For an option that allows linting files outside of your TSConfig file(s), see [`EXPERIMENTAL_useProjectService`](#experimental_useprojectservice).
Copy file name to clipboardExpand all lines: docs/users/Shared_Configurations.mdx
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -240,6 +240,9 @@ module.exports = {
240
240
</TabItem>
241
241
</Tabs>
242
242
243
+
Note that `stylistic` does not replace `recommended` or `strict`.
244
+
`stylistic` adds additional rules.
245
+
243
246
See [`configs/stylistic.ts`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic.ts) for the exact contents of this config.
244
247
245
248
### `stylistic-type-checked`
@@ -266,6 +269,9 @@ module.exports = {
266
269
</TabItem>
267
270
</Tabs>
268
271
272
+
Note that `stylistic-type-checked` does not replace `recommended-type-checked` or `strict-type-checked`.
273
+
`stylistic-type-checked` adds additional rules.
274
+
269
275
See [`configs/stylistic-type-checked.ts`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic-type-checked.ts) for the exact contents of this config.
0 commit comments