@@ -108,35 +108,37 @@ npm install eslint-plugin-import --save-dev
108
108
109
109
### Config - Legacy (` .eslintrc ` )
110
110
111
- All rules are off by default. However, you may configure them manually
112
- in your ` .eslintrc.(yml|json|js) ` , or extend one of the canned configs:
111
+ All rules are off by default. However, you may extend one of the preset configs, or configure them manually in your ` .eslintrc.(yml|json|js) ` .
113
112
114
- ``` yaml
115
- ---
116
- extends :
117
- - eslint:recommended
118
- - plugin:import/recommended
119
- # alternatively, 'recommended' is the combination of these two rule sets:
120
- - plugin:import/errors
121
- - plugin:import/warnings
122
-
123
- # or configure manually:
124
- plugins :
125
- - import
126
-
127
- rules :
128
- import/no-unresolved : [2, { commonjs: true, amd: true }]
129
- import/named : 2
130
- import/namespace : 2
131
- import/default : 2
132
- import/export : 2
133
- # etc...
113
+ - Extending a preset config:
114
+
115
+ ``` jsonc
116
+ {
117
+ " extends" : [
118
+ " eslint:recommended" ,
119
+ " plugin:import/recommended" ,
120
+ ],
121
+ }
122
+ ```
123
+
124
+ - Configuring manually:
125
+
126
+ ``` jsonc
127
+ {
128
+ " rules" : {
129
+ " import/no-unresolved" : [" error" , { " commonjs" : true , " amd" : true }]
130
+ " import/named" : " error" ,
131
+ " import/namespace" : " error" ,
132
+ " import/default" : " error" ,
133
+ " import/export" : " error" ,
134
+ // etc...
135
+ },
136
+ },
134
137
```
135
138
136
139
### Config - Flat (` eslint.config.js ` )
137
140
138
- All rules are off by default. However, you may configure them manually
139
- in your ` eslint.config.(js|cjs|mjs) ` , or extend one of the canned configs:
141
+ All rules are off by default. However, you may configure them manually in your ` eslint.config.(js|cjs|mjs) ` , or extend one of the preset configs:
140
142
141
143
``` js
142
144
import importPlugin from ' eslint-plugin-import' ;
@@ -166,18 +168,23 @@ You may use the following snippet or assemble your own config using the granular
166
168
167
169
Make sure you have installed [ ` @typescript-eslint/parser ` ] and [ ` eslint-import-resolver-typescript ` ] which are used in the following configuration.
168
170
169
- ``` yaml
170
- extends :
171
- - eslint:recommended
172
- - plugin:import/recommended
173
- # the following lines do the trick
174
- - plugin:import/typescript
175
- settings :
176
- import/resolver :
177
- # You will also need to install and configure the TypeScript resolver
178
- # See also https://github.com/import-js/eslint-import-resolver-typescript#configuration
179
- typescript : true
180
- node : true
171
+ ``` jsonc
172
+ {
173
+ " extends" : [
174
+ " eslint:recommended" ,
175
+ " plugin:import/recommended" ,
176
+ // the following lines do the trick
177
+ " plugin:import/typescript" ,
178
+ ],
179
+ " settings" : {
180
+ " import/resolver" : {
181
+ // You will also need to install and configure the TypeScript resolver
182
+ // See also https://github.com/import-js/eslint-import-resolver-typescript#configuration
183
+ " typescript" : true ,
184
+ " node" : true ,
185
+ },
186
+ },
187
+ }
181
188
```
182
189
183
190
[ `@typescript-eslint/parser` ] : https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser
@@ -206,6 +213,16 @@ You can reference resolvers in several ways (in order of precedence):
206
213
207
214
- as a conventional ` eslint-import-resolver ` name, like ` eslint-import-resolver-foo ` :
208
215
216
+ ``` jsonc
217
+ // .eslintrc
218
+ {
219
+ " settings" : {
220
+ // uses 'eslint-import-resolver-foo':
221
+ " import/resolver" : " foo" ,
222
+ },
223
+ }
224
+ ```
225
+
209
226
``` yaml
210
227
# .eslintrc.yml
211
228
settings :
@@ -226,6 +243,15 @@ module.exports = {
226
243
227
244
- with a full npm module name, like ` my-awesome-npm-module ` :
228
245
246
+ ``` jsonc
247
+ // .eslintrc
248
+ {
249
+ " settings" : {
250
+ " import/resolver" : " my-awesome-npm-module" ,
251
+ },
252
+ }
253
+ ```
254
+
229
255
``` yaml
230
256
# .eslintrc.yml
231
257
settings :
@@ -321,11 +347,15 @@ In practice, this means rules other than [`no-unresolved`](./docs/rules/no-unres
321
347
322
348
` no-unresolved ` has its own [ ` ignore ` ] ( ./docs/rules/no-unresolved.md#ignore ) setting.
323
349
324
- ` ` ` yaml
325
- settings:
326
- import/ignore:
327
- - \. coffee$ # fraught with parse errors
328
- - \. (scss|less|css)$ # can't parse unprocessed CSS modules, either
350
+ ``` jsonc
351
+ {
352
+ " settings" : {
353
+ " import/ignore" : [
354
+ " \. coffee$" , // fraught with parse errors
355
+ " \. (scss|less|css)$" , // can't parse unprocessed CSS modules, either
356
+ ],
357
+ },
358
+ }
329
359
```
330
360
331
361
### ` import/core-modules `
@@ -344,10 +374,13 @@ import 'electron' // without extra config, will be flagged as unresolved!
344
374
that would otherwise be unresolved. To avoid this, you may provide ` electron ` as a
345
375
core module:
346
376
347
- ` ` ` yaml
348
- # .eslintrc.yml
349
- settings:
350
- import/core-modules: [ electron ]
377
+ ``` jsonc
378
+ // .eslintrc
379
+ {
380
+ " settings" : {
381
+ " import/core-modules" : [" electron" ],
382
+ },
383
+ }
351
384
```
352
385
353
386
In Electron's specific case, there is a shared config named ` electron `
@@ -380,11 +413,15 @@ dependency parser will require and use the map key as the parser instead of the
380
413
configured ESLint parser. This is useful if you're inter-op-ing with TypeScript
381
414
directly using webpack, for example:
382
415
383
- ` ` ` yaml
384
- # .eslintrc.yml
385
- settings:
386
- import/parsers:
387
- "@typescript-eslint/parser": [ .ts, .tsx ]
416
+ ``` jsonc
417
+ // .eslintrc
418
+ {
419
+ " settings" : {
420
+ " import/parsers" : {
421
+ " @typescript-eslint/parser" : [" .ts" , " .tsx" ],
422
+ },
423
+ },
424
+ }
388
425
```
389
426
390
427
In this case, [ ` @typescript-eslint/parser ` ] ( https://www.npmjs.com/package/@typescript-eslint/parser )
@@ -414,20 +451,28 @@ For long-lasting processes, like [`eslint_d`] or [`eslint-loader`], however, it'
414
451
415
452
If you never use [ ` eslint_d ` ] or [ ` eslint-loader ` ] , you may set the cache lifetime to ` Infinity ` and everything should be fine:
416
453
417
- ` ` ` yaml
418
- # .eslintrc.yml
419
- settings:
420
- import/cache:
421
- lifetime: ∞ # or Infinity
454
+ ``` jsonc
455
+ // .eslintrc
456
+ {
457
+ " settings" : {
458
+ " import/cache" : {
459
+ " lifetime" : " ∞" , // or Infinity, in a JS config
460
+ },
461
+ },
462
+ }
422
463
```
423
464
424
465
Otherwise, set some integer, and cache entries will be evicted after that many seconds have elapsed:
425
466
426
- ` ` ` yaml
427
- # .eslintrc.yml
428
- settings:
429
- import/cache:
430
- lifetime: 5 # 30 is the default
467
+ ``` jsonc
468
+ // .eslintrc
469
+ {
470
+ " settings" : {
471
+ " import/cache" : {
472
+ " lifetime" : 5 , // 30 is the default
473
+ },
474
+ },
475
+ }
431
476
```
432
477
433
478
[ `eslint_d` ] : https://www.npmjs.com/package/eslint_d
@@ -441,10 +486,13 @@ By default, any package referenced from [`import/external-module-folders`](#impo
441
486
442
487
For example, if your packages in a monorepo are all in ` @scope ` , you can configure ` import/internal-regex ` like this
443
488
444
- ` ` ` yaml
445
- # .eslintrc.yml
446
- settings:
447
- import/internal-regex: ^@scope/
489
+ ``` jsonc
490
+ // .eslintrc
491
+ {
492
+ " settings" : {
493
+ " import/internal-regex" : " ^@scope/" ,
494
+ },
495
+ }
448
496
```
449
497
450
498
## SublimeLinter-eslint
0 commit comments