Skip to content

Commit 1a736f0

Browse files
committed
chore: migrate to native eslint flat config
1 parent 29f8384 commit 1a736f0

3 files changed

Lines changed: 86 additions & 84 deletions

File tree

.eslintrc.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 83 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,23 @@
1-
import { FlatCompat } from '@eslint/eslintrc';
21
import js from '@eslint/js';
3-
import tsEslintPlugin from '@typescript-eslint/eslint-plugin';
4-
import { createRequire } from 'node:module';
5-
import path from 'node:path';
6-
import { fileURLToPath } from 'node:url';
2+
import { defineConfig } from 'eslint/config';
3+
import prettier from 'eslint-config-prettier';
4+
import jest from 'eslint-plugin-jest';
5+
import react from 'eslint-plugin-react';
6+
import reactHooks from 'eslint-plugin-react-hooks';
7+
import globals from 'globals';
8+
import tseslint from 'typescript-eslint';
79

8-
const __filename = fileURLToPath(import.meta.url);
9-
const __dirname = path.dirname(__filename);
10-
const require = createRequire(import.meta.url);
11-
12-
const compat = new FlatCompat({
13-
baseDirectory: __dirname,
14-
recommendedConfig: js.configs.recommended,
15-
allConfig: js.configs.all,
16-
});
17-
18-
const recommendedTsRulesConfig = tsEslintPlugin.configs.recommended;
19-
const recommendedTsRulesObject = Array.isArray(recommendedTsRulesConfig)
20-
? recommendedTsRulesConfig.reduce(
21-
(rules, config) => ({ ...rules, ...(config.rules || {}) }),
22-
{},
23-
)
24-
: recommendedTsRulesConfig?.rules || {};
25-
const recommendedTsRules = new Set(Object.keys(recommendedTsRulesObject));
26-
const noopRule = {
27-
meta: { type: 'problem', docs: {}, schema: [] },
28-
create: () => ({}),
29-
};
30-
31-
function normalizeConfig(config) {
32-
const next = { ...config };
33-
34-
if (next.plugins?.['@typescript-eslint']) {
35-
next.plugins = { ...next.plugins };
36-
delete next.plugins['@typescript-eslint'];
37-
}
38-
39-
if (next.rules) {
40-
next.rules = Object.fromEntries(
41-
Object.entries(next.rules).filter(([ruleName]) => {
42-
if (ruleName.startsWith('@babel/')) {
43-
return false;
44-
}
45-
if (!ruleName.startsWith('@typescript-eslint/')) {
46-
return true;
47-
}
48-
return recommendedTsRules.has(ruleName);
49-
}),
50-
);
51-
}
52-
53-
return next;
54-
}
55-
56-
export default [
10+
export default defineConfig([
11+
{
12+
plugins: {
13+
'@typescript-eslint': tseslint.plugin,
14+
},
15+
},
16+
{
17+
linterOptions: {
18+
reportUnusedDisableDirectives: 'off',
19+
},
20+
},
5721
{
5822
ignores: [
5923
'node_modules/',
@@ -65,27 +29,83 @@ export default [
6529
'.dumi/',
6630
'.doc/',
6731
'.vercel/',
68-
'.eslintrc.js',
6932
'src/index.d.ts',
7033
],
7134
},
7235
{
36+
files: ['**/*.{js,jsx,ts,tsx}'],
37+
extends: [
38+
js.configs.recommended,
39+
react.configs.flat.recommended,
40+
react.configs.flat['jsx-runtime'],
41+
prettier,
42+
],
7343
plugins: {
74-
'@typescript-eslint': {
75-
...tsEslintPlugin,
76-
rules: {
77-
...tsEslintPlugin.rules,
78-
'consistent-type-exports': noopRule,
79-
},
44+
'react-hooks': reactHooks,
45+
},
46+
languageOptions: {
47+
globals: {
48+
...globals.browser,
49+
...globals.node,
50+
},
51+
},
52+
settings: {
53+
react: {
54+
version: 'detect',
8055
},
8156
},
57+
rules: {
58+
'no-async-promise-executor': 'off',
59+
'no-empty-pattern': 'off',
60+
'no-irregular-whitespace': 'off',
61+
'no-prototype-builtins': 'off',
62+
'no-useless-escape': 'off',
63+
'no-extra-boolean-cast': 'off',
64+
'no-undef': 'off',
65+
'no-unused-vars': 'off',
66+
'react/no-find-dom-node': 'off',
67+
'react/display-name': 'off',
68+
'react/no-unknown-property': 'off',
69+
'react/prop-types': 'off',
70+
'react-hooks/exhaustive-deps': 'warn',
71+
'react-hooks/rules-of-hooks': 'error',
72+
},
8273
},
83-
...compat.config(require('./.eslintrc.js')).map(normalizeConfig),
8474
{
75+
files: ['**/*.{ts,tsx}'],
76+
extends: [...tseslint.configs.recommended],
8577
rules: {
78+
'@typescript-eslint/ban-ts-comment': 'off',
8679
'@typescript-eslint/no-empty-object-type': 'off',
80+
'@typescript-eslint/no-explicit-any': 'off',
8781
'@typescript-eslint/no-unsafe-function-type': 'off',
82+
'@typescript-eslint/no-unnecessary-type-constraint': 'off',
8883
'@typescript-eslint/no-unused-vars': 'off',
8984
},
9085
},
91-
];
86+
{
87+
files: ['src/**/*.{ts,tsx}'],
88+
languageOptions: {
89+
parserOptions: {
90+
projectService: true,
91+
tsconfigRootDir: import.meta.dirname,
92+
},
93+
},
94+
},
95+
{
96+
files: ['tests/**/*.{js,jsx,ts,tsx}', '**/*.{test,spec}.{js,jsx,ts,tsx}'],
97+
extends: [jest.configs['flat/recommended']],
98+
rules: {
99+
'jest/no-disabled-tests': 'off',
100+
'jest/no-done-callback': 'off',
101+
'jest/no-identical-title': 'off',
102+
'jest/expect-expect': 'off',
103+
'jest/no-alias-methods': 'off',
104+
'jest/no-conditional-expect': 'off',
105+
'jest/no-export': 'off',
106+
'jest/no-standalone-expect': 'off',
107+
'jest/valid-expect': 'off',
108+
'jest/valid-title': 'off',
109+
},
110+
},
111+
]);

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@
5353
"@rc-component/motion": "^1.1.4"
5454
},
5555
"devDependencies": {
56-
"@babel/eslint-parser": "^7.29.7",
57-
"@babel/eslint-plugin": "^7.29.7",
58-
"@eslint/eslintrc": "^3.3.5",
5956
"@eslint/js": "^9.39.4",
6057
"@rc-component/father-plugin": "^2.2.0",
6158
"@rc-component/np": "^1.0.4",
@@ -67,9 +64,6 @@
6764
"@types/node": "^26.0.1",
6865
"@types/react": "^19.2.17",
6966
"@types/react-dom": "^19.2.3",
70-
"@typescript-eslint/eslint-plugin": "^8.62.1",
71-
"@typescript-eslint/parser": "^8.62.1",
72-
"@umijs/fabric": "^4.0.1",
7367
"@umijs/test": "^4.6.68",
7468
"cross-env": "^10.1.0",
7569
"dumi": "^2.4.38",
@@ -78,9 +72,9 @@
7872
"eslint-plugin-jest": "^29.15.4",
7973
"eslint-plugin-react": "^7.37.5",
8074
"eslint-plugin-react-hooks": "^7.1.1",
81-
"eslint-plugin-unicorn": "^65.0.1",
8275
"father": "^4.6.24",
8376
"gh-pages": "^6.3.0",
77+
"globals": "^17.7.0",
8478
"husky": "^9.1.7",
8579
"jest": "^30.4.2",
8680
"jest-environment-jsdom": "^30.4.1",
@@ -90,7 +84,8 @@
9084
"react": "^19.2.7",
9185
"react-dom": "^19.2.7",
9286
"ts-node": "^10.9.1",
93-
"typescript": "^6.0.3"
87+
"typescript": "^6.0.3",
88+
"typescript-eslint": "^8.62.1"
9489
},
9590
"peerDependencies": {
9691
"react": ">=16.0.0",

0 commit comments

Comments
 (0)