1
- import { fromRoot , hasTypescript } from "@anolilab/package-json-utils" ;
1
+ import { fromRoot , hasTypescript , packageIsTypeModule } from "@anolilab/package-json-utils" ;
2
2
import type { Linter } from "eslint" ;
3
3
4
4
import { createConfigs } from "../../utils/create-config" ;
@@ -16,18 +16,16 @@ const config: Linter.Config = createConfigs([
16
16
} ,
17
17
plugins : [ "import" ] ,
18
18
rules : {
19
- // Static analysis:
20
-
21
- // ensure imports point to files/modules that can be resolved
19
+ // enforce a consistent style for type specifiers (inline or top-level)
22
20
// https://github.com/un-es/eslint-plugin-i/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/consistent-type-specifier-style.md
23
21
"import/consistent-type-specifier-style" : [ "error" , "prefer-top-level" ] ,
24
22
25
23
// ensure named imports coupled with named exports
26
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/default.md#when-not-to-use-it
24
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/default.md#when-not-to-use-it
27
25
"import/default" : "off" ,
28
26
29
- // ensure default import coupled with default export
30
- // https://github.com/benmosher /eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57 /docs/rules/dynamic-import-chunkname.md
27
+ // dynamic imports require a leading comment with a webpackChunkName
28
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/dynamic-import-chunkname.md
31
29
"import/dynamic-import-chunkname" : [
32
30
"off" ,
33
31
{
@@ -36,72 +34,75 @@ const config: Linter.Config = createConfigs([
36
34
} ,
37
35
] ,
38
36
39
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/export.md
37
+ // disallow invalid exports, e.g. multiple defaults
38
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/export.md
40
39
"import/export" : "error" ,
41
40
42
- // Helpful warnings:
43
-
44
- // disallow invalid exports, e.g. multiple defaults
45
- // https://github.com/benmosher/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md
41
+ // This rule enforces that all exports are declared at the bottom of the file.
42
+ // https://github.com/import-js/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md
46
43
"import/exports-last" : "error" ,
47
44
48
- // do not allow a default import name to match a named export
49
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/extensions.md
45
+ // Ensure consistent use of file extension within the import path
46
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/extensions.md
50
47
"import/extensions" : [
51
48
"error" ,
52
49
"ignorePackages" ,
53
- {
54
- cjs : "never" ,
55
- js : "never" ,
56
- jsx : "never" ,
57
- mjs : "never" ,
58
- } ,
50
+ packageIsTypeModule
51
+ ? {
52
+ cjs : "always" ,
53
+ js : "always" ,
54
+ jsx : "always" ,
55
+ mjs : "always" ,
56
+ }
57
+ : {
58
+ cjs : "never" ,
59
+ js : "never" ,
60
+ jsx : "never" ,
61
+ mjs : "never" ,
62
+ } ,
59
63
] ,
60
64
61
- // warn on accessing default export property names that are also named exports
62
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/first.md
65
+ // disallow non-import statements appearing before import statements
66
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/first.md
63
67
"import/first" : "error" ,
64
68
65
- // disallow use of jsdoc-marked-deprecated imports
66
- // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/group-exports.md
69
+ // Reports when named exports are not grouped together in a single export declaration
70
+ // or when multiple assignments to CommonJS module.exports or exports object are present
71
+ // in a single file.
72
+ // https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/group-exports.md
67
73
"import/group-exports" : "off" ,
68
74
69
- // Forbid the use of extraneous packages
70
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-extraneous-dependencies .md
75
+ // disallow non-import statements appearing before import statements
76
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/imports-first .md
71
77
// deprecated: use `import/first`
72
78
"import/imports-first" : "off" ,
73
79
74
- // Forbid mutable exports
75
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/max-dependencies.md
80
+ // Forbid modules to have too many dependencies
81
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/max-dependencies.md
76
82
"import/max-dependencies" : [ "off" , { max : 10 } ] ,
77
83
78
- // Module systems:
79
-
80
84
// disallow require()
81
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/named.md#when-not-to-use-it
85
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/named.md#when-not-to-use-it
82
86
"import/named" : "error" ,
83
87
84
88
// disallow AMD require/define
85
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/namespace.md
89
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/namespace.md
86
90
"import/namespace" : "off" ,
87
91
88
- // No Node.js builtin modules
89
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/newline-after-import.md
92
+ // Require a newline after the last import/require in a group
93
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/newline-after-import.md
90
94
"import/newline-after-import" : "error" ,
91
95
92
- // Style guide:
93
-
94
- // disallow non-import statements appearing before import statements
95
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
96
+ // Forbid import of modules using absolute paths
97
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-absolute-path.md
96
98
"import/no-absolute-path" : "error" ,
97
99
98
- // disallow non-import statements appearing before import statements
99
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md
100
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-amd.md
100
+ // disallow AMD require/define
101
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-amd.md
101
102
"import/no-amd" : "error" ,
102
103
103
- // disallow duplicate imports
104
- // https://github.com/benmosher /eslint-plugin-import/blob/d9b712ac7fd1fddc391f7b234827925c160d956f/docs/rules/no-anonymous-default-export.md
104
+ // Reports if a module's default export is unnamed
105
+ // https://github.com/import-js /eslint-plugin-import/blob/d9b712ac7fd1fddc391f7b234827925c160d956f/docs/rules/no-anonymous-default-export.md
105
106
"import/no-anonymous-default-export" : [
106
107
"off" ,
107
108
{
@@ -114,37 +115,37 @@ const config: Linter.Config = createConfigs([
114
115
} ,
115
116
] ,
116
117
117
- // disallow namespace imports
118
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-commonjs.md
119
- "import/no-commonjs" : "off" ,
118
+ // disallow require()
119
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/no-commonjs.md
120
+ "import/no-commonjs" : packageIsTypeModule ? "error" : "off" ,
120
121
121
- // Ensure consistent use of file extension within the import path
122
+ // Forbid cyclical dependencies between modules
122
123
// https://medium.com/@steven -lemon182/are-typescript-barrel-files-an-anti-pattern-72a713004250
123
124
"import/no-cycle" : [ "error" , { maxDepth : "∞" } ] ,
124
125
125
- // ensure absolute imports are above relative imports and that unassigned imports are ignored
126
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
127
- // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-default-export.md
126
+ // forbid default exports. this is a terrible rule, do not use it.
127
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-default-export.md
128
128
"import/no-default-export" : "off" ,
129
129
130
- // Require a newline after the last import/require in a group
131
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-deprecated.md
130
+ // disallow use of jsdoc-marked-deprecated imports
131
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/no-deprecated.md
132
132
"import/no-deprecated" : "off" ,
133
133
134
- // Require modules with a single export to use a default export
135
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-duplicates.md
134
+ // disallow duplicate imports
135
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/no-duplicates.md
136
136
"import/no-duplicates" : "error" ,
137
137
138
- // Restrict which files can be imported in a given folder
139
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-dynamic-require.md
138
+ // Forbid require() calls with expressions
139
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/no-dynamic-require.md
140
140
"import/no-dynamic-require" : "error" ,
141
141
142
- // Forbid modules to have too many dependencies
142
+ // Reports the use of empty named import blocks.
143
143
// https://github.com/un-es/eslint-plugin-i/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/no-empty-named-blocks.md
144
144
"import/no-empty-named-blocks" : "error" ,
145
145
146
- // Forbid import of modules using absolute paths
147
- // are treated both as absolute paths, and relative to process.cwd()
146
+ // Forbid the use of extraneous packages
147
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-extraneous-dependencies.md
148
+ // paths are treated both as absolute paths, and relative to process.cwd()
148
149
"import/no-extraneous-dependencies" : [
149
150
"error" ,
150
151
{
@@ -184,99 +185,118 @@ const config: Linter.Config = createConfigs([
184
185
} ,
185
186
] ,
186
187
187
- // Forbid require() calls with expressions
188
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-internal-modules.md
188
+ // prevent importing the submodules of other modules
189
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/no-internal-modules.md
189
190
"import/no-internal-modules" : [
190
191
"off" ,
191
192
{
192
193
allow : [ ] ,
193
194
} ,
194
195
] ,
195
196
196
- // prevent importing the submodules of other modules
197
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-mutable-exports.md
197
+ // Forbid mutable exports
198
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/no-mutable-exports.md
198
199
"import/no-mutable-exports" : "error" ,
199
200
200
201
// Warn if a module could be mistakenly parsed as a script by a consumer
201
202
// leveraging Unambiguous JavaScript Grammar
202
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/unambiguous.md
203
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/unambiguous.md
203
204
// this should not be enabled until this proposal has at least been *presented* to TC39.
204
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-named-as-default.md
205
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/no-named-as-default.md
205
206
"import/no-named-as-default" : "error" ,
206
207
207
- // Forbid Webpack loader syntax in imports
208
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-named-as-default-member.md
208
+ // warn on accessing default export property names that are also named exports
209
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/no-named-as-default-member.md
209
210
"import/no-named-as-default-member" : "error" ,
210
211
211
- // Prevent unassigned imports
212
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unassigned-import.md
213
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-default.md
212
+ // Prevent importing the default as if it were named
213
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-default.md
214
214
"import/no-named-default" : "error" ,
215
215
216
- // Prevent importing the default as if it were named
217
- // https://github.com/benmosher /eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/docs/rules/no-named-export.md
216
+ // Prohibit named exports. this is a terrible rule, do not use it.
217
+ // https://github.com/import-js /eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/docs/rules/no-named-export.md
218
218
"import/no-named-export" : "off" ,
219
219
220
- // Reports if a module's default export is unnamed
221
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-namespace.md
220
+ // disallow namespace imports
221
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/no-namespace.md
222
222
"import/no-namespace" : "error" ,
223
223
224
- // This rule enforces that all exports are declared at the bottom of the file.
225
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-nodejs-modules.md
224
+ // No Node.js builtin modules
225
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-nodejs-modules.md
226
+ // TODO: enable?
226
227
"import/no-nodejs-modules" : "off" ,
227
228
228
- // Reports when named exports are not grouped together in a single export declaration
229
- // or when multiple assignments to CommonJS const config or exports object are present
230
- // in a single file.
231
- // https://github.com/benmosher/eslint-plugin-import/blob/c34f14f67f077acd5a61b3da9c0b0de298d20059/docs/rules/no-relative-parent-imports.md
229
+ // Use this rule to prevent imports to folders in relative parent paths.
230
+ // https://github.com/import-js/eslint-plugin-import/blob/c34f14f67f077acd5a61b3da9c0b0de298d20059/docs/rules/no-relative-parent-imports.md
232
231
"import/no-relative-parent-imports" : "off" ,
233
232
234
- // forbid default exports. this is a terrible rule, do not use it.
235
- // https://github.com/benmosher /eslint-plugin-import/blob/master /docs/rules/no-restricted-paths.md
233
+ // Restrict which files can be imported in a given folder
234
+ // https://github.com/import-js /eslint-plugin-import/blob/main /docs/rules/no-restricted-paths.md
236
235
"import/no-restricted-paths" : "off" ,
237
236
238
- // Prohibit named exports. this is a terrible rule, do not use it.
239
- // https://github.com/benmosher /eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md
237
+ // Forbid a module from importing itself
238
+ // https://github.com/import-js /eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md
240
239
"import/no-self-import" : "error" ,
241
240
242
241
// Forbid a module from importing itself
243
242
// importing for side effects is perfectly acceptable, if you need side effects.
244
243
"import/no-unassigned-import" : "off" ,
245
244
246
- // Forbid cyclical dependencies between modules
247
- // https://github.com/benmosher/eslint-plugin-import/blob/d81f48a2506182738409805f5272eff4d77c9348/docs/rules/no-cycle.md
248
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
245
+ // ensure imports point to files/modules that can be resolved
246
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unresolved.md
249
247
"import/no-unresolved" : [ "error" , { caseSensitive : true , commonjs : true } ] ,
250
248
251
- // Ensures that there are no useless path segments
252
- // Note: you must disable the base rule as it can report incorrect errors
253
- "import/no-unused-modules" : "off" ,
249
+ // Reports modules without any exports, or with unused exports
250
+ // https://github.com/import-js/eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
251
+ "import/no-unused-modules" : [
252
+ packageIsTypeModule ? "error" : "off" ,
253
+ {
254
+ ignoreExports : [ ] ,
255
+ missingExports : true ,
256
+ unusedExports : true ,
257
+ } ,
258
+ ] ,
254
259
255
- // dynamic imports require a leading comment with a webpackChunkName
256
- // https://github.com/benmosher/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/no-useless-path-segments.md
257
- "import/no-useless-path-segments" : [ "error" , { commonjs : true , noUselessIndex : true } ] ,
260
+ // Reports the use of import declarations with CommonJS exports in any module except for the main module.
261
+ // https://github.com/import-js/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-import-module-exports.md
262
+ "import/no-import-module-exports" : [
263
+ packageIsTypeModule ? "off" : "error" ,
264
+ {
265
+ exceptions : [ ] ,
266
+ } ,
267
+ ] ,
258
268
259
- // Use this rule to prevent imports to folders in relative parent paths.
260
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md
269
+ // Use this rule to prevent importing packages through relative paths.
270
+ // https://github.com/import-js/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-relative-packages.md
271
+ "import/no-relative-packages" : "error" ,
272
+
273
+ // Ensures that there are no useless path segments
274
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-useless-path-segments.md
275
+ "import/no-useless-path-segments" : [ "error" , { commonjs : ! packageIsTypeModule , noUselessIndex : true } ] ,
276
+
277
+ // Forbid Webpack loader syntax in imports
278
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-webpack-loader-syntax.md
261
279
"import/no-webpack-loader-syntax" : "error" ,
262
280
263
- // Reports modules without any exports, or with unused exports
264
- // https://github.com/benmosher /eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
281
+ // ensure absolute imports are above relative imports and that unassigned imports are ignored
282
+ // https://github.com/import-js /eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
265
283
// simple-import-sort does this better
266
284
"import/order" : "off" ,
267
285
268
- // enforce a consistent style for type specifiers (inline or top-level)
269
- // https://github.com/un-es/eslint-plugin-i/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/consistent-type-specifier-style.md
270
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
286
+ // Require modules with a single export to use a default export
287
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/prefer-default-export.md
271
288
"import/prefer-default-export" : "error" ,
272
289
273
- // Reports the use of empty named import blocks.
290
+ // Warn if a module could be mistakenly parsed as a script by a consumer
291
+ // leveraging Unambiguous JavaScript Grammar
292
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/unambiguous.md
293
+ // this should not be enabled until this proposal has at least been *presented* to TC39.
274
294
// At the moment, it's not a thing.
275
295
"import/unambiguous" : "off" ,
276
296
} ,
277
297
settings : {
278
298
"import/core-modules" : [ ] ,
279
- // https://github.com/un-es/eslint-plugin-i/blob/master /docs/rules/extensions.md
299
+ // https://github.com/un-es/eslint-plugin-i/blob/main /docs/rules/extensions.md
280
300
"import/extensions" : [ ".js" , ".cjs" , ".mjs" , ".jsx" ] ,
281
301
// Ensure consistent use of file extension within the import path
282
302
"import/ignore" : [ "\\.(coffee|scss|css|less|hbs|svg|json)$" ] ,
@@ -304,7 +324,7 @@ const config: Linter.Config = createConfigs([
304
324
// Does not work when the TS definition exports a default const.
305
325
"import/default" : "off" ,
306
326
307
- // Disabled because of https://github.com/benmosher /eslint-plugin-import/issues/1590
327
+ // Disabled because of https://github.com/import-js /eslint-plugin-import/issues/1590
308
328
"import/export" : "off" ,
309
329
310
330
// Disabled as it doesn't work with TypeScript.
@@ -320,10 +340,10 @@ const config: Linter.Config = createConfigs([
320
340
} ,
321
341
] ,
322
342
323
- // This issue and some others: https://github.com/benmosher /eslint-plugin-import/issues/1341
343
+ // This issue and some others: https://github.com/import-js /eslint-plugin-import/issues/1341
324
344
"import/named" : "off" ,
325
345
326
- // Enforce consistent usage of type imports.
346
+ // ensure imports point to files/modules that can be resolved
327
347
"import/no-unresolved" : "off" ,
328
348
} ,
329
349
settings : {
0 commit comments