1
1
// @ts -check
2
2
3
- import { fixupConfigRules } from '@eslint/compat' ;
4
- import { FlatCompat } from '@eslint/eslintrc' ;
5
3
import js from '@eslint/js' ;
6
4
import { defineConfig , globalIgnores } from 'eslint/config' ;
7
5
import prettierConfig from 'eslint-config-prettier/flat' ;
6
+ import { importX } from 'eslint-plugin-import-x' ;
8
7
import jest from 'eslint-plugin-jest' ;
9
8
import * as jestFormatting from 'eslint-plugin-jest-formatting' ;
10
9
import globals from 'globals' ;
11
10
import tseslint from 'typescript-eslint' ;
12
11
13
- const compat = new FlatCompat ( {
14
- baseDirectory : import . meta. dirname ,
15
- } ) ;
16
-
17
12
const config = defineConfig (
18
13
js . configs . recommended ,
19
14
tseslint . configs . recommendedTypeChecked ,
15
+ importX . flatConfigs . recommended ,
16
+ importX . flatConfigs . typescript ,
20
17
{
21
18
name : 'Language options' ,
19
+ files : [ '**/*.{js,mjs,cjs,ts,mts}' ] ,
22
20
languageOptions : {
23
21
globals : {
24
22
...globals . node ,
25
23
} ,
24
+ ecmaVersion : 'latest' ,
25
+ sourceType : 'module' ,
26
26
parser : tseslint . parser ,
27
27
parserOptions : {
28
28
projectService : true ,
29
29
tsconfigRootDir : import . meta. dirname ,
30
30
} ,
31
31
} ,
32
32
} ,
33
- {
34
- // TODO: replace import with import-x
35
- name : 'Import plugin config' ,
36
- extends : fixupConfigRules ( compat . extends ( 'plugin:import/recommended' ) ) ,
37
-
38
- rules : {
39
- 'import/order' : [
40
- 'warn' ,
41
- {
42
- groups : [ 'builtin' , 'external' , 'parent' , 'sibling' , 'index' ] ,
43
- 'newlines-between' : 'always' ,
44
-
45
- alphabetize : {
46
- order : 'asc' ,
47
- caseInsensitive : false ,
48
- } ,
49
- } ,
50
- ] ,
51
-
52
- 'import/first' : 'error' ,
53
- 'import/no-empty-named-blocks' : 'error' ,
54
- 'import/no-extraneous-dependencies' : 'error' ,
55
- 'import/no-mutable-exports' : 'error' ,
56
- 'import/no-named-default' : 'error' ,
57
- 'import/no-relative-packages' : 'warn' ,
58
- } ,
59
- } ,
60
33
{
61
34
name : 'Rules overrides for all files' ,
62
35
rules : {
@@ -72,49 +45,40 @@ const config = defineConfig(
72
45
} ,
73
46
] ,
74
47
'@typescript-eslint/no-use-before-define' : 'off' ,
48
+
49
+ // Import
50
+ 'import-x/order' : [
51
+ 'warn' ,
52
+ {
53
+ groups : [ 'builtin' , 'external' , 'parent' , 'sibling' , 'index' ] ,
54
+ 'newlines-between' : 'always' ,
55
+
56
+ alphabetize : {
57
+ order : 'asc' ,
58
+ caseInsensitive : false ,
59
+ } ,
60
+ } ,
61
+ ] ,
62
+ 'import-x/first' : 'error' ,
63
+ 'import-x/no-empty-named-blocks' : 'error' ,
64
+ 'import-x/no-extraneous-dependencies' : 'error' ,
65
+ 'import-x/no-mutable-exports' : 'error' ,
66
+ 'import-x/no-named-default' : 'error' ,
67
+ 'import-x/no-relative-packages' : 'warn' ,
75
68
} ,
76
69
} ,
77
70
{
78
- name : 'Rule overrides for TypeScript files' ,
79
- files : [ '**/*.ts' , '**/*. mts'] ,
71
+ name : 'Rule overrides only for TypeScript files' ,
72
+ files : [ '**/*.{ts, mts} ' ] ,
80
73
rules : {
81
- // Import
82
- // Rules enabled by `import/recommended` but are better handled by
83
- // TypeScript and @typescript -eslint.
84
- 'import/default' : 'off' ,
85
- 'import/export' : 'off' ,
86
- 'import/namespace' : 'off' ,
87
- 'import/no-unresolved' : 'off' ,
74
+ // Rules enabled by `import-x/recommended` but are better handled by
75
+ // TypeScript and typescript-eslint.
76
+ 'import-x/default' : 'off' ,
77
+ 'import-x/export' : 'off' ,
78
+ 'import-x/namespace' : 'off' ,
79
+ 'import-x/no-unresolved' : 'off' ,
88
80
} ,
89
81
} ,
90
- // {
91
- // files: ['**/*.ts'],
92
- //
93
- // extends: fixupConfigRules(
94
- // compat.extends(
95
- // 'plugin:import/typescript'
96
- // )
97
- // ),
98
- //
99
- // rules: {
100
- // 'import/default': 'off',
101
- // 'import/export': 'off',
102
- // 'import/namespace': 'off',
103
- // 'import/no-unresolved': 'off',
104
- // },
105
- //
106
- // settings: {
107
- // 'import/resolver': {
108
- // node: {
109
- // extensions: ['.js', '.ts'],
110
- // },
111
- //
112
- // typescript: {
113
- // alwaysTryTypes: true,
114
- // },
115
- // },
116
- // },
117
- // },
118
82
{
119
83
name : 'Jest config' ,
120
84
files : [ '**/*.test.ts' , '**/*.test.js' ] ,
@@ -123,15 +87,15 @@ const config = defineConfig(
123
87
} ,
124
88
{
125
89
name : 'Plain JS' ,
126
- files : [ '**/*.js' , '**/*. mjs' , '**/*. cjs'] ,
90
+ files : [ '**/*.{js, mjs, cjs} ' ] ,
127
91
extends : [ tseslint . configs . disableTypeChecked ] ,
128
92
} ,
129
93
{
130
94
name : 'Config files' ,
131
- files : [ './*.js' , './*. cjs', './*.mjs' , '** /*.config.*js '] ,
95
+ files : [ '**/*rc*.{js,mjs, cjs} ' , '** /*.config.{js,cjs,mjs,ts} ' ] ,
132
96
rules : {
133
97
'@typescript-eslint/no-require-imports' : 'off' ,
134
- 'import/no-unresolved ' : 'off' ,
98
+ 'import-x /no-named-as-default-member ' : 'off' ,
135
99
} ,
136
100
} ,
137
101
globalIgnores ( [ '**/coverage/' , '**/dist/' ] ) ,
0 commit comments