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
This is a resolver for `eslint-plugin-import(-x)` plugin, not an ESLint plugin itself, it adds [`TypeScript`][] support to [`eslint-plugin-import`][] (Or maybe you want to try [`eslint-plugin-import-x`][] for faster speed)
15
+
This is a resolver for `eslint-plugin-import(-x)` plugin, not an ESLint plugin itself, it adds [`TypeScript`][] support to [`eslint-plugin-import`][]. (Or maybe you want to try [`eslint-plugin-import-x`][] for faster speed)
16
16
17
17
This means you can:
18
18
19
19
-`import`/`require` files with extension `.cts`/`.mts`/`.ts`/`.tsx`/`.d.cts`/`.d.mts`/`.d.ts`
20
20
- Use [`paths`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) defined in `tsconfig.json`
21
21
- Prefer resolving `@types/*` definitions over plain `.js`/`.jsx`
22
-
- Multiple tsconfigs support just like normal
22
+
- Multiple tsconfigs support, just like normal
23
23
-`imports/exports` fields support in `package.json`
24
24
25
25
## TOC <!-- omit in toc -->
@@ -50,9 +50,9 @@ This means you can:
50
50
51
51
## Notice
52
52
53
-
After version 2.0.0, `.d.ts` will take higher priority then normal `.js`/`.jsx` files on resolving `node_modules` packages in favor of `@types/*` definitions or its own definition.
53
+
After version 2.0.0, `.d.ts` will take higher priority than normal `.js`/`.jsx` files on resolving `node_modules` packages in favor of `@types/*` definitions or its own definition.
54
54
55
-
If you're facing some problems on rules `import/default` or `import/named` from [`eslint-plugin-import`][], do not post any issue here, because they are just working exactly as [expected](https://github.com/import-js/eslint-import-resolver-typescript/issues/31#issuecomment-539751607) on our sides, take[import-js/eslint-plugin-import#1525](https://github.com/import-js/eslint-plugin-import/issues/1525) as reference or post a new issue to[`eslint-plugin-import`][] instead.
55
+
If you're facing some problems with rules `import/default` or `import/named` from [`eslint-plugin-import`][], do not post any issue here, because they are working exactly as [expected](https://github.com/import-js/eslint-import-resolver-typescript/issues/31#issuecomment-539751607) on our side. Take[import-js/eslint-plugin-import#1525](https://github.com/import-js/eslint-plugin-import/issues/1525) as reference or post a new issue on[`eslint-plugin-import`][] instead.
56
56
57
57
## Installation
58
58
@@ -67,6 +67,9 @@ pnpm i -D eslint-plugin-import-x eslint-import-resolver-typescript
bun add -d eslint-plugin-import eslint-import-resolver-typescript
83
89
```
84
90
85
91
## Configuration
86
92
87
93
### `eslint.config.js`
88
94
89
-
If you are using `eslint-plugin-import-x@>=4.5.0`, you can use import/require to reference `eslint-import-resolver-typescript` directly in your ESLint flat config:
95
+
If you are using `eslint-plugin-import-x@>=4.5.0`, you can use `import`/`require` to reference `eslint-import-resolver-typescript` directly in your ESLint flat config:
alwaysTryTypes:true, //always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
106
+
alwaysTryTypes:true, //Always try to resolve types under `<root>@types` directory even if it doesn't contain any source code, like `@types/unist`
101
107
102
-
bun:true, //resolve Bun modules https://github.com/import-js/eslint-import-resolver-typescript#bun
108
+
bun:true, //Resolve Bun modules (https://github.com/import-js/eslint-import-resolver-typescript#bun)
103
109
104
110
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json or <root>/jsconfig.json by default
105
111
106
-
//use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json
112
+
//Use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json
107
113
project:'path/to/folder',
108
114
109
115
// Multiple tsconfigs/jsconfigs (Useful for monorepos, but discouraged in favor of `references` supported)
110
116
111
-
//use a glob pattern
117
+
//Use a glob pattern
112
118
project:'packages/*/{ts,js}config.json',
113
119
114
-
//use an array
120
+
//Use an array
115
121
project: [
116
122
'packages/module-a/tsconfig.json',
117
123
'packages/module-b/jsconfig.json',
118
124
],
119
125
120
-
//use an array of glob patterns
126
+
//Use an array of glob patterns
121
127
project: [
122
128
'packages/*/tsconfig.json',
123
129
'other-packages/*/jsconfig.json',
@@ -129,36 +135,36 @@ export default [
129
135
]
130
136
```
131
137
132
-
But if you are using `eslint-plugin-import` or the older version of `eslint-plugin-import-x`, you can't use require/import:
138
+
But if you are using `eslint-plugin-import` or the older version of `eslint-plugin-import-x`, you can't use `require`/`import`:
133
139
134
140
```js
135
-
// eslint.config.js, CommonJS is also supported
141
+
// eslint.config.js (CommonJS is also supported)
136
142
exportdefault [
137
143
{
138
144
settings: {
139
145
'import/resolver': {
140
146
typescript: {
141
-
alwaysTryTypes:true, //always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
147
+
alwaysTryTypes:true, //Always try to resolve types under `<root>@types` directory even if it doesn't contain any source code, like `@types/unist`
142
148
143
-
bun:true, //resolve Bun modules https://github.com/import-js/eslint-import-resolver-typescript#bun
149
+
bun:true, //Resolve Bun modules (https://github.com/import-js/eslint-import-resolver-typescript#bun)
144
150
145
151
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json or <root>/jsconfig.json by default
146
152
147
-
//use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json
153
+
//Use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json
148
154
project:'path/to/folder',
149
155
150
156
// Multiple tsconfigs/jsconfigs (Useful for monorepos, but discouraged in favor of `references` supported)
151
157
152
-
//use a glob pattern
158
+
//Use a glob pattern
153
159
project:'packages/*/{ts,js}config.json',
154
160
155
-
//use an array
161
+
//Use an array
156
162
project: [
157
163
'packages/module-a/tsconfig.json',
158
164
'packages/module-b/jsconfig.json',
159
165
],
160
166
161
-
//use an array of glob patterns
167
+
//Use an array of glob patterns
162
168
project: [
163
169
'packages/*/tsconfig.json',
164
170
'other-packages/*/jsconfig.json',
@@ -178,7 +184,7 @@ Add the following to your `.eslintrc` config:
178
184
{
179
185
"plugins": ["import"],
180
186
"rules": {
181
-
//turn on errors for missing imports
187
+
//Turn on errors for missing imports
182
188
"import/no-unresolved":"error",
183
189
},
184
190
"settings": {
@@ -187,27 +193,27 @@ Add the following to your `.eslintrc` config:
187
193
},
188
194
"import/resolver": {
189
195
"typescript": {
190
-
"alwaysTryTypes":true, //always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
196
+
"alwaysTryTypes":true, //Always try to resolve types under `<root>@types` directory even if it doesn't contain any source code, like `@types/unist`
191
197
192
-
"bun":true, //resolve Bun modules https://github.com/import-js/eslint-import-resolver-typescript#bun
198
+
"bun":true, //Resolve Bun modules (https://github.com/import-js/eslint-import-resolver-typescript#bun)
193
199
194
200
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json or <root>/jsconfig.json by default
195
201
196
-
//use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json
202
+
//Use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json
197
203
"project":"path/to/folder",
198
204
199
205
// Multiple tsconfigs (Useful for monorepos, but discouraged in favor of `references` supported)
200
206
201
-
//use a glob pattern
207
+
//Use a glob pattern
202
208
"project":"packages/*/{ts,js}config.json",
203
209
204
-
//use an array
210
+
//Use an array
205
211
"project": [
206
212
"packages/module-a/tsconfig.json",
207
213
"packages/module-b/jsconfig.json",
208
214
],
209
215
210
-
//use an array of glob patterns
216
+
//Use an array of glob patterns
211
217
"project": [
212
218
"packages/*/tsconfig.json",
213
219
"other-packages/*/jsconfig.json",
@@ -226,9 +232,9 @@ Add the following to your `.eslintrc` config:
226
232
227
233
Enable Bun built-in module resolution by choosing 1 out of these 3 options:
228
234
229
-
- Set the `bun: true` option, as shown in [Configuration](#configuration) above
230
-
- Run ESLint with `bun --bun eslint`
231
-
-[Configure `run.bun` in `bunfig.toml`](https://bun.sh/docs/runtime/bunfig#run-bun-auto-alias-node-to-bun)
235
+
- Set the `bun: true` option, as shown in [Configuration](#configuration) above.
236
+
- Run ESLint with `bun --bun eslint`.
237
+
-[Configure `run.bun` in `bunfig.toml`](https://bun.sh/docs/runtime/bunfig#run-bun-auto-alias-node-to-bun).
232
238
233
239
## Options from [`unrs-resolver`][]
234
240
@@ -324,11 +330,11 @@ Default:
324
330
325
331
### Other options
326
332
327
-
You can pass through other options of [`unrs-resolver`][] directly
333
+
You can pass through other options of [`unrs-resolver`][] directly.
328
334
329
335
### Default options
330
336
331
-
You can reuse `defaultConditionNames`, `defaultExtensions`, `defaultExtensionAlias` and `defaultMainFields` by `require/import` them directly
337
+
You can reuse `defaultConditionNames`, `defaultExtensions`, `defaultExtensionAlias`, and `defaultMainFields` by directly using `require`/`import`.
332
338
333
339
## Contributing
334
340
@@ -337,7 +343,7 @@ You can reuse `defaultConditionNames`, `defaultExtensions`, `defaultExtensionAli
337
343
- Make sure that `yarn lint` passes without conflicts.
338
344
- Make sure your code changes match our [type-coverage](https://github.com/plantain-00/type-coverage) settings: `yarn type-coverage`.
339
345
340
-
We have [GitHub Actions](https://github.com/import-js/eslint-import-resolver-typescript/actions) which will run the above commands on your PRs.
346
+
We have [GitHub Actions](https://github.com/import-js/eslint-import-resolver-typescript/actions), which will run the above commands on your PRs.
341
347
342
348
If either fails, we won't be able to merge your PR until it's fixed.
0 commit comments