1- import typescriptEslint from "@typescript-eslint/eslint-plugin" ;
2- import tsParser from "@typescript-eslint/parser" ;
3- import path from "node:path" ;
4- import { fileURLToPath } from "node:url" ;
5- import js from "@eslint/js" ;
6- import { FlatCompat } from "@eslint/eslintrc" ;
1+ import importPlugin from 'eslint-plugin-import' ;
2+ import globals from 'globals' ;
3+ import tsParser from '@typescript-eslint/parser' ;
4+ import eslintJs from '@eslint/js' ;
5+ import eslintTs from 'typescript-eslint' ;
76
8- const __filename = fileURLToPath ( import . meta. url ) ;
9- const __dirname = path . dirname ( __filename ) ;
10- const compat = new FlatCompat ( {
11- baseDirectory : __dirname ,
12- recommendedConfig : js . configs . recommended ,
13- allConfig : js . configs . all
14- } ) ;
7+ const tsFiles = [ '{src,test}/**/*.ts' ] ;
158
16- export default [ {
17- ignores : [ "lib" , "**/*.d.ts" ] ,
18- } , ...compat . extends (
19- "eslint:recommended" ,
20- "plugin:@typescript-eslint/eslint-recommended" ,
21- "plugin:@typescript-eslint/recommended" ,
22- ) . map ( config => ( {
23- ...config ,
24- files : [ "**/*.ts" , "**/*.tsx" ] ,
25- } ) ) , {
26- files : [ "**/*.ts" , "**/*.tsx" ] ,
9+ const languageOptions = {
10+ globals : {
11+ ...globals . node ,
12+ ...globals . jest ,
13+ } ,
14+ ecmaVersion : 2023 ,
15+ sourceType : 'module' ,
16+ } ;
2717
18+ const customTypescriptConfig = {
19+ files : tsFiles ,
2820 plugins : {
29- "@typescript-eslint" : typescriptEslint ,
21+ import : importPlugin ,
22+ 'import/parsers' : tsParser ,
3023 } ,
31-
3224 languageOptions : {
25+ ...languageOptions ,
3326 parser : tsParser ,
27+ parserOptions : {
28+ project : './tsconfig.json' ,
29+ } ,
30+ } ,
31+ settings : {
32+ 'import/parsers' : {
33+ '@typescript-eslint/parser' : [ '.ts' ] ,
34+ } ,
3435 } ,
35-
3636 rules : {
3737 "no-console" : "off" ,
38+ "@typescript-eslint/no-explicit-any" : "off" ,
3839 } ,
39- } ] ;
40+ ignores : [ '/lib' ] ,
41+ } ;
42+
43+ // Add the files for applying the recommended TypeScript configs
44+ // only for the Typescript files.
45+ // This is necessary when we have the multiple extensions files
46+ // (e.g. .ts, .tsx, .js, .cjs, .mjs, etc.).
47+ const recommendedTypeScriptConfigs = [
48+ ...eslintTs . configs . recommended . map ( ( config ) => ( {
49+ ...config ,
50+ files : tsFiles ,
51+ } ) ) ,
52+ ...eslintTs . configs . stylistic . map ( ( config ) => ( {
53+ ...config ,
54+ files : tsFiles ,
55+ } ) ) ,
56+ ] ;
57+
58+ export default [
59+ { ignores : [ 'docs/*' , 'build/*' , 'lib/*' , 'dist/*' ] } , // global ignores
60+ eslintJs . configs . recommended ,
61+ ...recommendedTypeScriptConfigs ,
62+ customTypescriptConfig ,
63+ ] ;
0 commit comments