@@ -4,35 +4,38 @@ import { fixupConfigRules } from '@eslint/compat';
44import { FlatCompat } from '@eslint/eslintrc' ;
55import js from '@eslint/js' ;
66import { 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' ;
710import globals from 'globals' ;
811import tseslint from 'typescript-eslint' ;
912
1013const compat = new FlatCompat ( {
1114 baseDirectory : import . meta. dirname ,
12- recommendedConfig : js . configs . recommended ,
1315} ) ;
1416
1517const config = defineConfig (
18+ js . configs . recommended ,
19+ tseslint . configs . recommendedTypeChecked ,
1620 {
21+ name : 'Language options' ,
1722 languageOptions : {
1823 globals : {
19- ...globals . es2019 ,
24+ ...globals . node ,
25+ } ,
26+ parser : tseslint . parser ,
27+ parserOptions : {
28+ projectService : true ,
29+ tsconfigRootDir : import . meta. dirname ,
2030 } ,
2131 } ,
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' ) ) ,
3237
3338 rules : {
34- 'max-lines-per-function' : 'off' ,
35-
3639 'import/order' : [
3740 'warn' ,
3841 {
@@ -55,54 +58,84 @@ const config = defineConfig(
5558 } ,
5659 } ,
5760 {
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' ,
7662 rules : {
77- '@typescript-eslint/explicit-function-return-type' : 'off' ,
63+ // Base
64+ 'max-lines-per-function' : 'off' ,
7865
66+ // TypeScript
67+ '@typescript-eslint/explicit-function-return-type' : 'off' ,
7968 '@typescript-eslint/no-unused-vars' : [
8069 'warn' ,
8170 {
8271 argsIgnorePattern : '^_' ,
8372 } ,
8473 ] ,
85-
8674 '@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.
8784 'import/default' : 'off' ,
8885 'import/export' : 'off' ,
8986 'import/namespace' : 'off' ,
9087 'import/no-unresolved' : 'off' ,
9188 } ,
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' ,
103135 } ,
104136 } ,
105- globalIgnores ( [ '**/coverage/' , '**/dist/' ] )
137+ globalIgnores ( [ '**/coverage/' , '**/dist/' ] ) ,
138+ prettierConfig // must always be the last one
106139) ;
107140
108141export default config ;
0 commit comments