@@ -3,27 +3,92 @@ import { FlatCompat } from '@eslint/eslintrc';
33import js from '@eslint/js' ;
44import typescriptEslint from '@typescript-eslint/eslint-plugin' ;
55import tsParser from '@typescript-eslint/parser' ;
6- import _import from 'eslint-plugin-import' ;
7- import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths' ;
6+ import eslintImport from 'eslint-plugin-import' ;
87import preferArrowFunctions from 'eslint-plugin-prefer-arrow-functions' ;
8+ import jestPlugin from 'eslint-plugin-jest' ;
99import globals from 'globals' ;
10-
1110import path from 'node:path' ;
12- import process from 'node:process' ;
1311import { fileURLToPath } from 'node:url' ;
1412
1513const __filename = fileURLToPath ( import . meta. url ) ;
1614const __dirname = path . dirname ( __filename ) ;
15+
16+ const jestGlobals = jestPlugin . envs ?. [ 'jest/globals' ] ?. globals ?? jestPlugin . environments ?. [ 'jest/globals' ] ?. globals ?? { } ;
17+
1718const compat = new FlatCompat ( {
1819 baseDirectory : __dirname ,
1920 recommendedConfig : js . configs . recommended ,
2021 allConfig : js . configs . all ,
2122} ) ;
2223
24+ const shared = {
25+ plugins : {
26+ '@typescript-eslint' : fixupPluginRules ( typescriptEslint ) ,
27+ 'prefer-arrow-functions' : preferArrowFunctions ,
28+ import : fixupPluginRules ( eslintImport ) ,
29+ } ,
30+
31+ languageOptions : {
32+ parser : tsParser ,
33+ ecmaVersion : 'latest' ,
34+ sourceType : 'module' ,
35+ globals : { ...globals . node } ,
36+ parserOptions : {
37+ project : path . join ( __dirname , 'tsconfig.json' ) ,
38+ tsconfigRootDir : __dirname ,
39+ } ,
40+ } ,
41+
42+ settings : {
43+ 'import/resolver' : {
44+ node : { extensions : [ '.js' , '.mjs' , '.ts' ] } ,
45+ typescript : {
46+ project : [ path . join ( __dirname , 'tsconfig.json' ) , path . join ( __dirname , 'tsconfig.spec.json' ) ] ,
47+ alwaysTryTypes : true ,
48+ } ,
49+ } ,
50+ 'import/parsers' : {
51+ '@typescript-eslint/parser' : [ '.ts' , '.tsx' ] ,
52+ } ,
53+ } ,
54+
55+ rules : {
56+ 'import/no-unresolved' : 'error' ,
57+ 'import/extensions' : [ 'error' , 'ignorePackages' , { ts : 'never' , tsx : 'never' , js : 'never' , mjs : 'never' } ] ,
58+ 'import/order' : [
59+ 'error' ,
60+ {
61+ groups : [ 'external' , [ 'builtin' , 'index' , 'sibling' , 'parent' , 'internal' ] , 'object' , 'type' ] ,
62+ alphabetize : { order : 'asc' , caseInsensitive : true } ,
63+ 'newlines-between' : 'always' ,
64+ } ,
65+ ] ,
66+ 'prefer-arrow-functions/prefer-arrow-functions' : [
67+ 'error' ,
68+ {
69+ allowNamedFunctions : false ,
70+ classPropertiesAllowed : false ,
71+ disallowPrototype : false ,
72+ returnStyle : 'unchanged' ,
73+ singleReturnOnly : false ,
74+ } ,
75+ ] ,
76+ 'prefer-template' : 'error' ,
77+ 'no-nested-ternary' : 'error' ,
78+ 'no-implicit-coercion' : [ 'error' , { boolean : true } ] ,
79+ '@typescript-eslint/naming-convention' : [
80+ 'error' ,
81+ { selector : 'typeLike' , format : [ 'PascalCase' ] } ,
82+ { selector : 'enum' , format : [ 'UPPER_CASE' ] } ,
83+ ] ,
84+ } ,
85+ } ;
86+
2387export default [
2488 {
25- ignores : process . env . CI ? [ '**/*.ejs' , '**/dist/' , '**/examples' ] : [ '**/*.ejs ', '**/dist/ ' ] ,
89+ ignores : [ '**/*.ejs' , '**/dist/** ' , '**/examples/**' , 'eslint.config.mjs ', 'jest.config.mjs ' ] ,
2690 } ,
91+
2792 ...fixupConfigRules (
2893 compat . extends (
2994 'eslint:recommended' ,
@@ -32,97 +97,45 @@ export default [
3297 'plugin:import/typescript' ,
3398 ) ,
3499 ) ,
100+
35101 {
36- plugins : {
37- '@typescript-eslint' : fixupPluginRules ( typescriptEslint ) ,
38- 'prefer-arrow-functions' : preferArrowFunctions ,
39- import : fixupPluginRules ( _import ) ,
40- 'no-relative-import-paths' : noRelativeImportPaths ,
41- } ,
102+ files : [ '**/*.ts' , '**/*.tsx' ] ,
103+ ...shared ,
104+ } ,
42105
106+ {
107+ files : [ 'tests/**/*.{ts,tsx}' , '**/*.test.{ts,tsx}' , '**/*.spec.{ts,tsx}' ] ,
108+ plugins : { ...shared . plugins , jest : jestPlugin } ,
43109 languageOptions : {
44- globals : {
45- ...globals . browser ,
46- } ,
47-
48- parser : tsParser ,
49- ecmaVersion : 'latest' ,
50- sourceType : 'module' ,
110+ ...shared . languageOptions ,
111+ globals : { ...shared . languageOptions . globals , ...jestGlobals } ,
51112 } ,
52-
53- settings : {
54- 'import/resolver' : {
55- typescript : {
56- alwaysTryTypes : true ,
57- project : './tsconfig.json' ,
58- } ,
59- } ,
60-
61- 'import/parsers' : {
62- '@typescript-eslint/parser' : [ '.ts' , '.tsx' ] ,
63- } ,
64- } ,
65-
113+ settings : shared . settings ,
66114 rules : {
67- 'import/no-unresolved' : 'error' ,
68-
69- 'import/order' : [
70- 'error' ,
71- {
72- groups : [ 'external' , [ 'builtin' , 'index' , 'sibling' , 'parent' , 'internal' ] , 'object' , 'type' ] ,
73- 'newlines-between' : 'always' ,
74- alphabetize : {
75- order : 'asc' ,
76- caseInsensitive : true ,
77- } ,
78- } ,
79- ] ,
80-
81- 'no-relative-import-paths/no-relative-import-paths' : [
82- 'error' ,
83- {
84- allowSameFolder : false ,
85- } ,
86- ] ,
87-
88- 'prefer-arrow-functions/prefer-arrow-functions' : [
89- 'error' ,
90- {
91- allowNamedFunctions : false ,
92- classPropertiesAllowed : false ,
93- disallowPrototype : false ,
94- returnStyle : 'unchanged' ,
95- singleReturnOnly : false ,
96- } ,
97- ] ,
98-
99- 'prefer-template' : 'error' ,
100- 'no-nested-ternary' : 'error' ,
101- 'no-implicit-coercion' : [ 'error' , { boolean : true } ] ,
102-
103- '@typescript-eslint/naming-convention' : [
104- 'error' ,
105- {
106- selector : 'typeLike' ,
107- format : [ 'PascalCase' ] ,
108- } ,
109- {
110- selector : 'enum' ,
111- format : [ 'UPPER_CASE' ] ,
112- } ,
113- ] ,
115+ ...shared . rules ,
116+ 'import/no-extraneous-dependencies' : [ 'error' , { devDependencies : true } ] ,
114117 } ,
115118 } ,
119+
116120 {
117- files : [ '**/.eslintrc.js' ] ,
121+ files : [ '*.config.{ts,js,mjs,cjs}' ] ,
122+ languageOptions : {
123+ ...shared . languageOptions ,
124+ parserOptions : { project : null } ,
125+ } ,
126+ rules : { 'import/no-unresolved' : 'off' } ,
127+ } ,
118128
129+ {
130+ files : [ 'jest-ejs-transform.cjs' ] ,
119131 languageOptions : {
132+ sourceType : 'script' ,
120133 globals : {
121- ...globals . node ,
134+ module : 'readonly' ,
135+ exports : 'readonly' ,
136+ require : 'readonly' ,
122137 } ,
123-
124- ecmaVersion : 5 ,
125- sourceType : 'commonjs' ,
126138 } ,
139+ rules : { 'no-undef' : 'off' } ,
127140 } ,
128141] ;
0 commit comments