@@ -4,35 +4,38 @@ import { fixupConfigRules } from '@eslint/compat';
4
4
import { FlatCompat } from '@eslint/eslintrc' ;
5
5
import js from '@eslint/js' ;
6
6
import { defineConfig , globalIgnores } from 'eslint/config' ;
7
+ import prettierConfig from 'eslint-config-prettier/flat' ;
8
+ import jest from 'eslint-plugin-jest' ;
9
+ import * as jestFormatting from 'eslint-plugin-jest-formatting' ;
7
10
import globals from 'globals' ;
8
11
import tseslint from 'typescript-eslint' ;
9
12
10
13
const compat = new FlatCompat ( {
11
14
baseDirectory : import . meta. dirname ,
12
- recommendedConfig : js . configs . recommended ,
13
15
} ) ;
14
16
15
17
const config = defineConfig (
18
+ js . configs . recommended ,
19
+ tseslint . configs . recommendedTypeChecked ,
16
20
{
21
+ name : 'Language options' ,
17
22
languageOptions : {
18
23
globals : {
19
- ...globals . es2019 ,
24
+ ...globals . node ,
25
+ } ,
26
+ parser : tseslint . parser ,
27
+ parserOptions : {
28
+ projectService : true ,
29
+ tsconfigRootDir : import . meta. dirname ,
20
30
} ,
21
31
} ,
22
-
23
- extends : fixupConfigRules (
24
- compat . extends (
25
- 'eslint:recommended' ,
26
- 'plugin:import/recommended' ,
27
- 'plugin:jest/recommended' ,
28
- 'plugin:jest-formatting/recommended' ,
29
- 'prettier'
30
- )
31
- ) ,
32
+ } ,
33
+ {
34
+ // TODO: replace import with import-x
35
+ name : 'Import plugin config' ,
36
+ extends : fixupConfigRules ( compat . extends ( 'plugin:import/recommended' ) ) ,
32
37
33
38
rules : {
34
- 'max-lines-per-function' : 'off' ,
35
-
36
39
'import/order' : [
37
40
'warn' ,
38
41
{
@@ -55,54 +58,84 @@ const config = defineConfig(
55
58
} ,
56
59
} ,
57
60
{
58
- files : [ '**/*.ts' ] ,
59
-
60
- languageOptions : {
61
- parser : tseslint . parser ,
62
- parserOptions : {
63
- project : './tsconfig.eslint.json' ,
64
- tsconfigRootDir : import . meta. dirname ,
65
- } ,
66
- } ,
67
-
68
- extends : fixupConfigRules (
69
- compat . extends (
70
- 'plugin:@typescript-eslint/recommended' ,
71
- 'plugin:@typescript-eslint/recommended-type-checked' ,
72
- 'plugin:import/typescript'
73
- )
74
- ) ,
75
-
61
+ name : 'Rules overrides for all files' ,
76
62
rules : {
77
- '@typescript-eslint/explicit-function-return-type' : 'off' ,
63
+ // Base
64
+ 'max-lines-per-function' : 'off' ,
78
65
66
+ // TypeScript
67
+ '@typescript-eslint/explicit-function-return-type' : 'off' ,
79
68
'@typescript-eslint/no-unused-vars' : [
80
69
'warn' ,
81
70
{
82
71
argsIgnorePattern : '^_' ,
83
72
} ,
84
73
] ,
85
-
86
74
'@typescript-eslint/no-use-before-define' : 'off' ,
75
+ } ,
76
+ } ,
77
+ {
78
+ name : 'Rule overrides for TypeScript files' ,
79
+ files : [ '**/*.ts' , '**/*.mts' ] ,
80
+ rules : {
81
+ // Import
82
+ // Rules enabled by `import/recommended` but are better handled by
83
+ // TypeScript and @typescript -eslint.
87
84
'import/default' : 'off' ,
88
85
'import/export' : 'off' ,
89
86
'import/namespace' : 'off' ,
90
87
'import/no-unresolved' : 'off' ,
91
88
} ,
92
-
93
- settings : {
94
- 'import/resolver' : {
95
- node : {
96
- extensions : [ '.js' , '.ts' ] ,
97
- } ,
98
-
99
- typescript : {
100
- alwaysTryTypes : true ,
101
- } ,
102
- } ,
89
+ } ,
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
+ {
119
+ name : 'Jest config' ,
120
+ files : [ '**/*.test.ts' , '**/*.test.js' ] ,
121
+ ...jest . configs [ 'flat/recommended' ] ,
122
+ ...jestFormatting . configs [ 'flat/recommended' ] ,
123
+ } ,
124
+ {
125
+ name : 'Plain JS' ,
126
+ files : [ '**/*.js' , '**/*.mjs' , '**/*.cjs' ] ,
127
+ extends : [ tseslint . configs . disableTypeChecked ] ,
128
+ } ,
129
+ {
130
+ name : 'Config files' ,
131
+ files : [ './*.js' , './*.cjs' , './*.mjs' , '**/*.config.*js' ] ,
132
+ rules : {
133
+ '@typescript-eslint/no-require-imports' : 'off' ,
134
+ 'import/no-unresolved' : 'off' ,
103
135
} ,
104
136
} ,
105
- globalIgnores ( [ '**/coverage/' , '**/dist/' ] )
137
+ globalIgnores ( [ '**/coverage/' , '**/dist/' ] ) ,
138
+ prettierConfig // must always be the last one
106
139
) ;
107
140
108
141
export default config ;
0 commit comments