1
- import { fromRoot , hasTypescript , packageIsTypeModule } from "@anolilab/package-json-utils" ;
1
+ import { fromRoot , packageIsTypeModule , projectPath } from "@anolilab/package-json-utils" ;
2
2
import type { Linter } from "eslint" ;
3
3
4
4
import { createConfigs } from "../../utils/create-config" ;
@@ -62,12 +62,14 @@ const config: Linter.Config = createConfigs([
62
62
js : "always" ,
63
63
jsx : "always" ,
64
64
mjs : "always" ,
65
+ json : "always" ,
65
66
}
66
67
: {
67
68
cjs : "never" ,
68
69
js : "never" ,
69
70
jsx : "never" ,
70
71
mjs : "never" ,
72
+ json : "always" ,
71
73
} ,
72
74
] ,
73
75
@@ -86,7 +88,11 @@ const config: Linter.Config = createConfigs([
86
88
// deprecated: use `import/first`
87
89
"import/imports-first" : "off" ,
88
90
89
- // Forbid modules to have too many dependencies
91
+ // "import/max-dependencies" is not super useful
92
+ // Either you will disable the eslint rule because it's "normal"
93
+ // to have a lot of dependencies or feel compelled to reduce the number of imports.
94
+ // It's already visible that a file has many imports and that ideally they should be
95
+ // less imports, no need for ESLint, let's keep ESLint for more valuable things.
90
96
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/max-dependencies.md
91
97
"import/max-dependencies" : [ "off" , { max : 10 } ] ,
92
98
@@ -283,8 +289,10 @@ const config: Linter.Config = createConfigs([
283
289
"import/no-relative-packages" : "error" ,
284
290
285
291
// Ensures that there are no useless path segments
292
+ // TODO: Create a PR to fix commonjs option, when eslint --fix is run, it throws an error on the no-useless-path-segments.js:118
293
+ // @see https://github.com/import-js/eslint-plugin-import/pull/2886
286
294
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-useless-path-segments.md
287
- "import/no-useless-path-segments" : [ "error" , { commonjs : ! packageIsTypeModule , noUselessIndex : true } ] ,
295
+ "import/no-useless-path-segments" : [ "error" , { commonjs : false , noUselessIndex : true } ] ,
288
296
289
297
// Forbid Webpack loader syntax in imports
290
298
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-webpack-loader-syntax.md
@@ -312,22 +320,22 @@ const config: Linter.Config = createConfigs([
312
320
"import/extensions" : [ ".js" , ".cjs" , ".mjs" , ".jsx" ] ,
313
321
// Ensure consistent use of file extension within the import path
314
322
"import/ignore" : [ "\\.(coffee|scss|css|less|hbs|svg|json)$" ] ,
323
+ } ,
324
+ } ,
325
+ type : "all" ,
326
+ } ,
327
+ {
328
+ config : {
329
+ settings : {
315
330
"import/resolver" : {
316
- node : {
317
- extensions : [ ".mjs" , ".js" , ".json" , ".cjs" , ".jsx" ] ,
331
+ "@jsenv/eslint-import-resolver" : {
332
+ rootDirectoryUrl : projectPath ,
333
+ packageConditions : [ "node" , "import" ] ,
318
334
} ,
319
- ...( hasTypescript
320
- ? {
321
- typescript : {
322
- alwaysTryTypes : true , // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
323
- project : fromRoot ( "tsconfig.json" ) ,
324
- } ,
325
- }
326
- : { } ) ,
327
335
} ,
328
336
} ,
329
337
} ,
330
- type : "all " ,
338
+ type : "javascript " ,
331
339
} ,
332
340
{
333
341
config : {
@@ -347,8 +355,11 @@ const config: Linter.Config = createConfigs([
347
355
js : "never" ,
348
356
jsx : "never" ,
349
357
mjs : "never" ,
358
+ cjs : "never" ,
350
359
ts : "never" ,
351
360
tsx : "never" ,
361
+ json : "always" ,
362
+ svg : "always" ,
352
363
} ,
353
364
] ,
354
365
@@ -372,10 +383,10 @@ const config: Linter.Config = createConfigs([
372
383
373
384
// Append 'ts' extensions to 'import/resolver' setting
374
385
"import/resolver" : {
375
- node : {
376
- extensions : [ ".mjs" , ".cjs" , ".js" , ".json" , ".ts" , ".d.ts" ] ,
386
+ typescript : {
387
+ alwaysTryTypes : true , // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
388
+ project : fromRoot ( "tsconfig.json" ) ,
377
389
} ,
378
- typescript : true ,
379
390
} ,
380
391
} ,
381
392
} ,
0 commit comments