From f57dc1e0cf7d2212f106337eb91d5e5e69d07893 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 29 Jun 2026 18:19:34 +0800 Subject: [PATCH 01/16] chore: update maintenance dependencies --- .github/dependabot.yml | 8 +++++ README.md | 2 +- README.zh-CN.md | 2 +- eslint.config.mjs | 79 ++++++++++++++++++++++++++++++++++++++++++ global.d.ts | 58 +++++++++++++++++++++++++++++++ package.json | 35 ++++++++++++------- react-compat.d.ts | 16 +++++++++ tests/refs.spec.tsx | 2 +- tsconfig.json | 54 ++++++++++------------------- 9 files changed, 206 insertions(+), 50 deletions(-) create mode 100644 eslint.config.mjs create mode 100644 global.d.ts create mode 100644 react-compat.d.ts diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3b730ef99..5e6c7faab 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,6 +8,10 @@ updates: time: '21:00' timezone: Asia/Shanghai open-pull-requests-limit: 10 + groups: + npm-dependencies: + patterns: + - '*' - package-ecosystem: github-actions directory: '/' @@ -17,3 +21,7 @@ updates: time: '21:00' timezone: Asia/Shanghai open-pull-requests-limit: 10 + groups: + github-actions: + patterns: + - '*' diff --git a/README.md b/README.md index 90d236768..b4e6ca591 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

@rc-component/table

-

Ant Design Part of the Ant Design ecosystem.

+

Ant Design Part of the Ant Design ecosystem.

📋 Low-level table primitives for React, maintained in the Ant Design ecosystem.

diff --git a/README.zh-CN.md b/README.zh-CN.md index c31da3443..e9a9f762e 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,6 +1,6 @@

@rc-component/table

-

Ant Design Ant Design 生态的一部分。

+

Ant Design Ant Design 生态的一部分。

📋 React 底层表格基础组件,服务于复杂数据展示。

diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 000000000..b25fb5dd0 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,79 @@ +import { FlatCompat } from '@eslint/eslintrc'; +import js from '@eslint/js'; +import tsEslintPlugin from '@typescript-eslint/eslint-plugin'; +import { createRequire } from 'node:module'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const require = createRequire(import.meta.url); + +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all, +}); + +const recommendedTsRules = new Set(Object.keys(tsEslintPlugin.configs.recommended.rules || {})); +const noopRule = { + meta: { type: 'problem', docs: {}, schema: [] }, + create: () => ({}), +}; + +function normalizeConfig(config) { + const next = { ...config }; + + if (next.plugins?.['@typescript-eslint']) { + next.plugins = { + ...next.plugins, + '@typescript-eslint': { + ...next.plugins['@typescript-eslint'], + rules: { + ...next.plugins['@typescript-eslint'].rules, + 'ban-types': noopRule, + }, + }, + }; + } + + if (next.rules) { + next.rules = Object.fromEntries( + Object.entries(next.rules).filter(([ruleName]) => { + if (!ruleName.startsWith('@typescript-eslint/')) { + return true; + } + return recommendedTsRules.has(ruleName) || ruleName === '@typescript-eslint/ban-types'; + }), + ); + } + + return next; +} + +export default [ + { + ignores: [ + 'node_modules/', + 'coverage/', + 'es/', + 'lib/', + 'dist/', + 'docs-dist/', + '.dumi/', + '.doc/', + '.vercel/', + '.eslintrc.js', + 'src/index.d.ts', + ], + }, + ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), + { + rules: { + '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/no-empty-object-type': 'off', + '@typescript-eslint/no-unsafe-function-type': 'off', + '@typescript-eslint/no-unused-vars': 'off', + }, + }, +]; diff --git a/global.d.ts b/global.d.ts new file mode 100644 index 000000000..e4a99d8a1 --- /dev/null +++ b/global.d.ts @@ -0,0 +1,58 @@ +/// +/// +/// +/// +/// + +declare module '*.css'; +declare module '*.less'; +declare module 'jsonp'; + +declare namespace JSX { + type Element = React.JSX.Element; + interface ElementClass extends React.JSX.ElementClass {} + interface ElementAttributesProperty extends React.JSX.ElementAttributesProperty {} + interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {} + type LibraryManagedAttributes = React.JSX.LibraryManagedAttributes; + interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {} + interface IntrinsicClassAttributes extends React.JSX.IntrinsicClassAttributes {} + interface IntrinsicElements extends React.JSX.IntrinsicElements {} +} + +declare namespace jest { + interface Matchers { + lastCalledWith(...expected: unknown[]): R; + nthCalledWith(nthCall: number, ...expected: unknown[]): R; + toBeCalled(): R; + toBeCalledTimes(expected: number): R; + toBeCalledWith(...expected: unknown[]): R; + } +} + +declare const vi: { + fn: any = (...args: any[]) => any>( + implementation?: T, + ) => jest.MockedFunction; + mock: (moduleName: string, factory?: (importOriginal: () => Promise) => unknown) => void; + spyOn: typeof jest.spyOn; + useFakeTimers: () => void; + useRealTimers: () => void; + advanceTimersByTime: (msToRun: number) => void; + clearAllTimers: () => void; + runAllTimers: () => void; + importActual: (moduleName: string) => Promise; + clearAllMocks: () => void; + resetAllMocks: () => void; + restoreAllMocks: () => void; +}; + +declare const describe: any; +declare const it: any; +declare const test: any; +declare const beforeEach: any; +declare const afterEach: any; +declare const beforeAll: any; +declare const afterAll: any; +declare const expect: any; + +declare module 'moment/locale/zh-cn'; diff --git a/package.json b/package.json index 16865994a..0e58c68c2 100644 --- a/package.json +++ b/package.json @@ -65,17 +65,17 @@ "@rc-component/tooltip": "^1.4.0", "@testing-library/dom": "^10.4.1", "@testing-library/jest-dom": "^6.9.1", - "@testing-library/react": "^15.0.7", - "@types/jest": "^29.5.14", + "@testing-library/react": "^16.3.2", + "@types/jest": "^30.0.0", "@types/node": "^26.0.1", - "@types/react": "^18.3.31", - "@types/react-dom": "^18.3.7", - "@types/responselike": "^1.0.0", - "@types/styled-components": "^5.1.32", + "@types/react": "^19.2.17", + "@types/react-dom": "^19.2.3", + "@types/responselike": "^1.0.3", + "@types/styled-components": "^5.1.36", "@umijs/fabric": "^4.0.1", "@vitest/coverage-v8": "^4.1.9", "dumi": "^2.4.35", - "eslint": "^8.57.1", + "eslint": "^9.39.4", "father": "^4.6.23", "gh-pages": "^6.3.0", "glob": "^13.0.6", @@ -83,18 +83,29 @@ "immutability-helper": "^3.0.0", "jsdom": "^29.1.1", "less": "^4.6.7", - "lint-staged": "^16.4.0", + "lint-staged": "^17.0.8", "prettier": "^3.9.0", - "react": "^18.3.1", + "react": "^19.2.7", "react-dnd": "^2.5.4", "react-dnd-html5-backend": "^2.5.4", - "react-dom": "^18.3.1", + "react-dom": "^19.2.7", "react-resizable": "^3.0.5", "react-window": "^1.8.5", "regenerator-runtime": "^0.14.0", "styled-components": "^6.1.1", - "typescript": "^5.9.3", - "vitest": "^4.1.9" + "typescript": "^6.0.3", + "vitest": "^4.1.9", + "@eslint/eslintrc": "^3.3.5", + "@eslint/js": "^9.39.4", + "eslint-plugin-react": "^7.37.5", + "eslint-plugin-react-hooks": "^7.1.1", + "eslint-config-prettier": "^10.1.8", + "@babel/eslint-parser": "^7.29.7", + "@babel/eslint-plugin": "^7.29.7", + "@typescript-eslint/eslint-plugin": "^8.62.0", + "@typescript-eslint/parser": "^8.62.0", + "eslint-plugin-jest": "^29.15.3", + "eslint-plugin-unicorn": "^65.0.1" }, "peerDependencies": { "react": ">=18.0.0", diff --git a/react-compat.d.ts b/react-compat.d.ts new file mode 100644 index 000000000..ff05aa1bd --- /dev/null +++ b/react-compat.d.ts @@ -0,0 +1,16 @@ +import * as React from 'react'; + +declare module 'react' { + type ReactText = string | number; + function useRef(): React.MutableRefObject; + function isValidElement

(object: {} | null | undefined): object is React.ReactElement

; + function cloneElement

( + element: React.ReactElement

, + props?: (Partial

& React.Attributes) | null, + ...children: React.ReactNode[] + ): React.ReactElement

; +} + +declare module 'react-dom' { + function hydrate(element: React.ReactNode, container: Element | DocumentFragment): void; +} diff --git a/tests/refs.spec.tsx b/tests/refs.spec.tsx index c5a240dbf..44019b980 100644 --- a/tests/refs.spec.tsx +++ b/tests/refs.spec.tsx @@ -14,7 +14,7 @@ describe('Table.Ref', () => { }, scrollIntoView() { // eslint-disable-next-line @typescript-eslint/no-this-alias - scrollIntoViewElement = this; + scrollIntoViewElement = this as unknown as HTMLElement; }, }); }); diff --git a/tsconfig.json b/tsconfig.json index 967a67218..4de511e5c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,38 +8,27 @@ "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": [ - "src/*" - ], - "@@/*": [ - ".dumi/tmp/*" - ], - "@rc-component/table": [ - "src/index.ts" - ], - "@rc-component/table/es": [ - "src" - ], - "@rc-component/table/es/*": [ - "src/*" - ], - "rc-table": [ - "src/index.ts" - ], - "rc-table/es": [ - "src" - ], - "rc-table/es/*": [ - "src/*" - ] + "@/*": ["src/*"], + "@@/*": [".dumi/tmp/*"], + "@rc-component/table": ["src/index.ts"], + "@rc-component/table/es": ["src"], + "@rc-component/table/es/*": ["src/*"], + "rc-table": ["src/index.ts"], + "rc-table/es": ["src"], + "rc-table/es/*": ["src/*"] }, - "types": [ - "vitest/globals", - "@testing-library/jest-dom" - ], - "ignoreDeprecations": "5.0" + "ignoreDeprecations": "6.0", + "noImplicitAny": false, + "strictNullChecks": false, + "strictPropertyInitialization": false, + "strictFunctionTypes": false, + "strict": false, + "noImplicitThis": false, + "strictBindCallApply": false }, "include": [ + "react-compat.d.ts", + "global.d.ts", ".fatherrc.ts", ".dumirc.ts", "typings.d.ts", @@ -51,10 +40,5 @@ "./tests/**/*.tsx", "tests/__mocks__/shadowTest.tsx" ], - "exclude": [ - "./vitest.config.mts", - "docs-dist", - "lib", - "es" - ] + "exclude": ["./vitest.config.mts", "docs-dist", "lib", "es"] } From 0324e536caf21e98153cc88264960aa082ac0b5f Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 10:21:07 +0800 Subject: [PATCH 02/16] fix: align TypeScript and ESLint compatibility --- eslint.config.mjs | 24 ++++++++++++++---------- global.d.ts | 9 --------- tsconfig.json | 23 +++++++++++------------ 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index b25fb5dd0..d85381ec3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -25,16 +25,8 @@ function normalizeConfig(config) { const next = { ...config }; if (next.plugins?.['@typescript-eslint']) { - next.plugins = { - ...next.plugins, - '@typescript-eslint': { - ...next.plugins['@typescript-eslint'], - rules: { - ...next.plugins['@typescript-eslint'].rules, - 'ban-types': noopRule, - }, - }, - }; + next.plugins = { ...next.plugins }; + delete next.plugins['@typescript-eslint']; } if (next.rules) { @@ -67,6 +59,18 @@ export default [ 'src/index.d.ts', ], }, + { + plugins: { + '@typescript-eslint': { + ...tsEslintPlugin, + rules: { + ...tsEslintPlugin.rules, + 'ban-types': noopRule, + 'consistent-type-exports': noopRule, + }, + }, + }, + }, ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), { rules: { diff --git a/global.d.ts b/global.d.ts index e4a99d8a1..85e4e4e75 100644 --- a/global.d.ts +++ b/global.d.ts @@ -46,13 +46,4 @@ declare const vi: { restoreAllMocks: () => void; }; -declare const describe: any; -declare const it: any; -declare const test: any; -declare const beforeEach: any; -declare const afterEach: any; -declare const beforeAll: any; -declare const afterAll: any; -declare const expect: any; - declare module 'moment/locale/zh-cn'; diff --git a/tsconfig.json b/tsconfig.json index 4de511e5c..09728d378 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,30 +1,29 @@ { "compilerOptions": { "target": "esnext", - "moduleResolution": "node", - "baseUrl": "./", + "moduleResolution": "bundler", "jsx": "react", "declaration": true, "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": ["src/*"], - "@@/*": [".dumi/tmp/*"], - "@rc-component/table": ["src/index.ts"], - "@rc-component/table/es": ["src"], - "@rc-component/table/es/*": ["src/*"], - "rc-table": ["src/index.ts"], - "rc-table/es": ["src"], - "rc-table/es/*": ["src/*"] + "@/*": ["./src/*"], + "@@/*": ["./.dumi/tmp/*"], + "@rc-component/table": ["./src/index.ts"], + "@rc-component/table/es": ["./src"], + "@rc-component/table/es/*": ["./src/*"], + "rc-table": ["./src/index.ts"], + "rc-table/es": ["./src"], + "rc-table/es/*": ["./src/*"] }, - "ignoreDeprecations": "6.0", "noImplicitAny": false, "strictNullChecks": false, "strictPropertyInitialization": false, "strictFunctionTypes": false, "strict": false, "noImplicitThis": false, - "strictBindCallApply": false + "strictBindCallApply": false, + "module": "ESNext" }, "include": [ "react-compat.d.ts", From 3e52ee843be9b37d86ff5be19d176050bdc3e153 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 10:51:18 +0800 Subject: [PATCH 03/16] chore: use testing-library dom events --- package.json | 24 ++++++++++++------------ tests/Cell.spec.tsx | 3 ++- tests/ExpandRow.spec.jsx | 3 ++- tests/FixedColumn.spec.tsx | 3 ++- tests/GroupingColumns.spec.jsx | 3 ++- tests/Hover.spec.tsx | 3 ++- tests/Scroll.spec.jsx | 3 ++- tests/Sticky.spec.jsx | 3 ++- tests/Summary.spec.tsx | 3 ++- tests/Table.spec.jsx | 3 ++- tests/Virtual.spec.tsx | 3 ++- tests/classComponent.spec.tsx | 3 ++- tests/semantic.spec.tsx | 3 ++- 13 files changed, 36 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 0e58c68c2..3a9ca211e 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,10 @@ "clsx": "^2.1.1" }, "devDependencies": { + "@babel/eslint-parser": "^7.29.7", + "@babel/eslint-plugin": "^7.29.7", + "@eslint/eslintrc": "^3.3.5", + "@eslint/js": "^9.39.4", "@rc-component/dropdown": "^1.0.2", "@rc-component/father-plugin": "^2.2.0", "@rc-component/menu": "^1.4.1", @@ -72,10 +76,17 @@ "@types/react-dom": "^19.2.3", "@types/responselike": "^1.0.3", "@types/styled-components": "^5.1.36", + "@typescript-eslint/eslint-plugin": "^8.62.0", + "@typescript-eslint/parser": "^8.62.0", "@umijs/fabric": "^4.0.1", "@vitest/coverage-v8": "^4.1.9", "dumi": "^2.4.35", "eslint": "^9.39.4", + "eslint-config-prettier": "^10.1.8", + "eslint-plugin-jest": "^29.15.3", + "eslint-plugin-react": "^7.37.5", + "eslint-plugin-react-hooks": "^7.1.1", + "eslint-plugin-unicorn": "^65.0.1", "father": "^4.6.23", "gh-pages": "^6.3.0", "glob": "^13.0.6", @@ -94,18 +105,7 @@ "regenerator-runtime": "^0.14.0", "styled-components": "^6.1.1", "typescript": "^6.0.3", - "vitest": "^4.1.9", - "@eslint/eslintrc": "^3.3.5", - "@eslint/js": "^9.39.4", - "eslint-plugin-react": "^7.37.5", - "eslint-plugin-react-hooks": "^7.1.1", - "eslint-config-prettier": "^10.1.8", - "@babel/eslint-parser": "^7.29.7", - "@babel/eslint-plugin": "^7.29.7", - "@typescript-eslint/eslint-plugin": "^8.62.0", - "@typescript-eslint/parser": "^8.62.0", - "eslint-plugin-jest": "^29.15.3", - "eslint-plugin-unicorn": "^65.0.1" + "vitest": "^4.1.9" }, "peerDependencies": { "react": ">=18.0.0", diff --git a/tests/Cell.spec.tsx b/tests/Cell.spec.tsx index 737e9b7db..d746b8603 100644 --- a/tests/Cell.spec.tsx +++ b/tests/Cell.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { render, fireEvent } from '@testing-library/react'; +import { render } from '@testing-library/react'; import Table from '../src'; describe('Table.Cell', () => { diff --git a/tests/ExpandRow.spec.jsx b/tests/ExpandRow.spec.jsx index d15eaa15b..eaaa5f2b2 100644 --- a/tests/ExpandRow.spec.jsx +++ b/tests/ExpandRow.spec.jsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { render, fireEvent, act } from '@testing-library/react'; +import { render, act } from '@testing-library/react'; import { resetWarned, spyElementPrototype } from '@rc-component/util'; import Table from '../src'; diff --git a/tests/FixedColumn.spec.tsx b/tests/FixedColumn.spec.tsx index 9ef416f67..63e9c1241 100644 --- a/tests/FixedColumn.spec.tsx +++ b/tests/FixedColumn.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { render, fireEvent, act } from '@testing-library/react'; +import { render, act } from '@testing-library/react'; import { _rs } from '@rc-component/resize-observer'; import Table, { type ColumnsType } from '../src'; import { RowColSpanWithFixed, RowColSpanWithFixed2 } from './__mocks__/shadowTest'; diff --git a/tests/GroupingColumns.spec.jsx b/tests/GroupingColumns.spec.jsx index 13f984244..4135d9c92 100644 --- a/tests/GroupingColumns.spec.jsx +++ b/tests/GroupingColumns.spec.jsx @@ -1,4 +1,5 @@ -import { render, act, fireEvent } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { render, act } from '@testing-library/react'; import React from 'react'; import Table from '../src'; diff --git a/tests/Hover.spec.tsx b/tests/Hover.spec.tsx index 7029feb74..69c395093 100644 --- a/tests/Hover.spec.tsx +++ b/tests/Hover.spec.tsx @@ -1,4 +1,5 @@ -import { render, fireEvent } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import { resetWarned, toArray } from '@rc-component/util'; import React from 'react'; import Table from '../src'; diff --git a/tests/Scroll.spec.jsx b/tests/Scroll.spec.jsx index dfe96087c..f4538e4d0 100644 --- a/tests/Scroll.spec.jsx +++ b/tests/Scroll.spec.jsx @@ -1,4 +1,5 @@ -import { render, fireEvent } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import { spyElementPrototypes } from '@rc-component/util'; import React from 'react'; import { act } from '@testing-library/react'; diff --git a/tests/Sticky.spec.jsx b/tests/Sticky.spec.jsx index 44e1fd080..c0f97943c 100644 --- a/tests/Sticky.spec.jsx +++ b/tests/Sticky.spec.jsx @@ -1,4 +1,5 @@ -import { render, fireEvent, createEvent } from '@testing-library/react'; +import { fireEvent, createEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import { spyElementPrototypes } from '@rc-component/util'; import React from 'react'; import { act } from '@testing-library/react'; diff --git a/tests/Summary.spec.tsx b/tests/Summary.spec.tsx index 90c89cbf3..c4eabea22 100644 --- a/tests/Summary.spec.tsx +++ b/tests/Summary.spec.tsx @@ -1,4 +1,5 @@ -import { render, fireEvent } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import React from 'react'; import Table from '../src'; diff --git a/tests/Table.spec.jsx b/tests/Table.spec.jsx index dc3b5d5ca..29510baec 100644 --- a/tests/Table.spec.jsx +++ b/tests/Table.spec.jsx @@ -1,4 +1,5 @@ -import { render, fireEvent } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import { resetWarned } from '@rc-component/util'; import React from 'react'; import { VariableSizeGrid as Grid } from 'react-window'; diff --git a/tests/Virtual.spec.tsx b/tests/Virtual.spec.tsx index 8eb49c165..69b62f6df 100644 --- a/tests/Virtual.spec.tsx +++ b/tests/Virtual.spec.tsx @@ -1,4 +1,5 @@ -import { act, fireEvent, render } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { act, render } from '@testing-library/react'; import { _rs as onResize } from '@rc-component/resize-observer'; import { resetWarned, spyElementPrototypes } from '@rc-component/util'; import React from 'react'; diff --git a/tests/classComponent.spec.tsx b/tests/classComponent.spec.tsx index 6018ef838..6128a2f7d 100644 --- a/tests/classComponent.spec.tsx +++ b/tests/classComponent.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { render, fireEvent } from '@testing-library/react'; +import { render } from '@testing-library/react'; import Table from '../src'; describe('Table.ClassComponent', () => { diff --git a/tests/semantic.spec.tsx b/tests/semantic.spec.tsx index 878a621f7..7718db340 100644 --- a/tests/semantic.spec.tsx +++ b/tests/semantic.spec.tsx @@ -1,4 +1,5 @@ -import { render, fireEvent } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import React from 'react'; import Table, { TableProps } from '../src'; describe('support classNames and styles', () => { From a3b1e8fb74c44618d7821708c45e32d881a17261 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 11:16:25 +0800 Subject: [PATCH 04/16] test: keep react testing event behavior --- tests/Cell.spec.tsx | 3 +-- tests/ExpandRow.spec.jsx | 3 +-- tests/FixedColumn.spec.tsx | 3 +-- tests/GroupingColumns.spec.jsx | 3 +-- tests/Hover.spec.tsx | 3 +-- tests/Scroll.spec.jsx | 3 +-- tests/Sticky.spec.jsx | 3 +-- tests/Summary.spec.tsx | 3 +-- tests/Table.spec.jsx | 3 +-- tests/Virtual.spec.tsx | 3 +-- tests/classComponent.spec.tsx | 3 +-- tests/semantic.spec.tsx | 3 +-- 12 files changed, 12 insertions(+), 24 deletions(-) diff --git a/tests/Cell.spec.tsx b/tests/Cell.spec.tsx index d746b8603..737e9b7db 100644 --- a/tests/Cell.spec.tsx +++ b/tests/Cell.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { render } from '@testing-library/react'; +import { render, fireEvent } from '@testing-library/react'; import Table from '../src'; describe('Table.Cell', () => { diff --git a/tests/ExpandRow.spec.jsx b/tests/ExpandRow.spec.jsx index eaaa5f2b2..d15eaa15b 100644 --- a/tests/ExpandRow.spec.jsx +++ b/tests/ExpandRow.spec.jsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { render, act } from '@testing-library/react'; +import { render, fireEvent, act } from '@testing-library/react'; import { resetWarned, spyElementPrototype } from '@rc-component/util'; import Table from '../src'; diff --git a/tests/FixedColumn.spec.tsx b/tests/FixedColumn.spec.tsx index 63e9c1241..9ef416f67 100644 --- a/tests/FixedColumn.spec.tsx +++ b/tests/FixedColumn.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { render, act } from '@testing-library/react'; +import { render, fireEvent, act } from '@testing-library/react'; import { _rs } from '@rc-component/resize-observer'; import Table, { type ColumnsType } from '../src'; import { RowColSpanWithFixed, RowColSpanWithFixed2 } from './__mocks__/shadowTest'; diff --git a/tests/GroupingColumns.spec.jsx b/tests/GroupingColumns.spec.jsx index 4135d9c92..13f984244 100644 --- a/tests/GroupingColumns.spec.jsx +++ b/tests/GroupingColumns.spec.jsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { render, act } from '@testing-library/react'; +import { render, act, fireEvent } from '@testing-library/react'; import React from 'react'; import Table from '../src'; diff --git a/tests/Hover.spec.tsx b/tests/Hover.spec.tsx index 69c395093..7029feb74 100644 --- a/tests/Hover.spec.tsx +++ b/tests/Hover.spec.tsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { render, fireEvent } from '@testing-library/react'; import { resetWarned, toArray } from '@rc-component/util'; import React from 'react'; import Table from '../src'; diff --git a/tests/Scroll.spec.jsx b/tests/Scroll.spec.jsx index f4538e4d0..dfe96087c 100644 --- a/tests/Scroll.spec.jsx +++ b/tests/Scroll.spec.jsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { render, fireEvent } from '@testing-library/react'; import { spyElementPrototypes } from '@rc-component/util'; import React from 'react'; import { act } from '@testing-library/react'; diff --git a/tests/Sticky.spec.jsx b/tests/Sticky.spec.jsx index c0f97943c..44e1fd080 100644 --- a/tests/Sticky.spec.jsx +++ b/tests/Sticky.spec.jsx @@ -1,5 +1,4 @@ -import { fireEvent, createEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { render, fireEvent, createEvent } from '@testing-library/react'; import { spyElementPrototypes } from '@rc-component/util'; import React from 'react'; import { act } from '@testing-library/react'; diff --git a/tests/Summary.spec.tsx b/tests/Summary.spec.tsx index c4eabea22..90c89cbf3 100644 --- a/tests/Summary.spec.tsx +++ b/tests/Summary.spec.tsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { render, fireEvent } from '@testing-library/react'; import React from 'react'; import Table from '../src'; diff --git a/tests/Table.spec.jsx b/tests/Table.spec.jsx index 29510baec..dc3b5d5ca 100644 --- a/tests/Table.spec.jsx +++ b/tests/Table.spec.jsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { render, fireEvent } from '@testing-library/react'; import { resetWarned } from '@rc-component/util'; import React from 'react'; import { VariableSizeGrid as Grid } from 'react-window'; diff --git a/tests/Virtual.spec.tsx b/tests/Virtual.spec.tsx index 69b62f6df..8eb49c165 100644 --- a/tests/Virtual.spec.tsx +++ b/tests/Virtual.spec.tsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; import { _rs as onResize } from '@rc-component/resize-observer'; import { resetWarned, spyElementPrototypes } from '@rc-component/util'; import React from 'react'; diff --git a/tests/classComponent.spec.tsx b/tests/classComponent.spec.tsx index 6128a2f7d..6018ef838 100644 --- a/tests/classComponent.spec.tsx +++ b/tests/classComponent.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { render } from '@testing-library/react'; +import { render, fireEvent } from '@testing-library/react'; import Table from '../src'; describe('Table.ClassComponent', () => { diff --git a/tests/semantic.spec.tsx b/tests/semantic.spec.tsx index 7718db340..878a621f7 100644 --- a/tests/semantic.spec.tsx +++ b/tests/semantic.spec.tsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { render, fireEvent } from '@testing-library/react'; import React from 'react'; import Table, { TableProps } from '../src'; describe('support classNames and styles', () => { From 0aa50292aa2b6dcae4a138a6f037f01432331976 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 19:04:28 +0800 Subject: [PATCH 05/16] chore: address review comments --- eslint.config.mjs | 22 +++++++--------------- react-compat.d.ts | 4 ---- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index d85381ec3..e8504e279 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -15,11 +15,11 @@ const compat = new FlatCompat({ allConfig: js.configs.all, }); -const recommendedTsRules = new Set(Object.keys(tsEslintPlugin.configs.recommended.rules || {})); -const noopRule = { - meta: { type: 'problem', docs: {}, schema: [] }, - create: () => ({}), -}; +const recommendedTsRulesConfig = tsEslintPlugin.configs.recommended; +const recommendedTsRulesObject = Array.isArray(recommendedTsRulesConfig) + ? recommendedTsRulesConfig.reduce((rules, config) => ({ ...rules, ...(config.rules || {}) }), {}) + : recommendedTsRulesConfig?.rules || {}; +const recommendedTsRules = new Set(Object.keys(recommendedTsRulesObject)); function normalizeConfig(config) { const next = { ...config }; @@ -35,7 +35,7 @@ function normalizeConfig(config) { if (!ruleName.startsWith('@typescript-eslint/')) { return true; } - return recommendedTsRules.has(ruleName) || ruleName === '@typescript-eslint/ban-types'; + return recommendedTsRules.has(ruleName); }), ); } @@ -61,20 +61,12 @@ export default [ }, { plugins: { - '@typescript-eslint': { - ...tsEslintPlugin, - rules: { - ...tsEslintPlugin.rules, - 'ban-types': noopRule, - 'consistent-type-exports': noopRule, - }, - }, + '@typescript-eslint': tsEslintPlugin, }, }, ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), { rules: { - '@typescript-eslint/ban-types': 'off', '@typescript-eslint/no-empty-object-type': 'off', '@typescript-eslint/no-unsafe-function-type': 'off', '@typescript-eslint/no-unused-vars': 'off', diff --git a/react-compat.d.ts b/react-compat.d.ts index ff05aa1bd..c509fe40e 100644 --- a/react-compat.d.ts +++ b/react-compat.d.ts @@ -10,7 +10,3 @@ declare module 'react' { ...children: React.ReactNode[] ): React.ReactElement

; } - -declare module 'react-dom' { - function hydrate(element: React.ReactNode, container: Element | DocumentFragment): void; -} From 05432630157f99b79abcc4f1c6dfb872f3329950 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 19:16:59 +0800 Subject: [PATCH 06/16] fix: keep compatible eslint export rule --- eslint.config.mjs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index e8504e279..7f8ca4ced 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -20,6 +20,10 @@ const recommendedTsRulesObject = Array.isArray(recommendedTsRulesConfig) ? recommendedTsRulesConfig.reduce((rules, config) => ({ ...rules, ...(config.rules || {}) }), {}) : recommendedTsRulesConfig?.rules || {}; const recommendedTsRules = new Set(Object.keys(recommendedTsRulesObject)); +const noopRule = { + meta: { type: 'problem', docs: {}, schema: [] }, + create: () => ({}), +}; function normalizeConfig(config) { const next = { ...config }; @@ -61,7 +65,13 @@ export default [ }, { plugins: { - '@typescript-eslint': tsEslintPlugin, + '@typescript-eslint': { + ...tsEslintPlugin, + rules: { + ...tsEslintPlugin.rules, + 'consistent-type-exports': noopRule, + }, + }, }, }, ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), From af1d6346c3d827bc5181e4e294a24c7bb30b18bc Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 19:32:32 +0800 Subject: [PATCH 07/16] chore: address review suggestion --- tests/refs.spec.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/refs.spec.tsx b/tests/refs.spec.tsx index 44019b980..2afcb72f7 100644 --- a/tests/refs.spec.tsx +++ b/tests/refs.spec.tsx @@ -12,9 +12,9 @@ describe('Table.Ref', () => { scrollTo: (_: any, param: any) => { scrollParam = param; }, - scrollIntoView() { + scrollIntoView(this: HTMLElement) { // eslint-disable-next-line @typescript-eslint/no-this-alias - scrollIntoViewElement = this as unknown as HTMLElement; + scrollIntoViewElement = this; }, }); }); From 8bd26c641056578ae2d0576682c3c13a35e856e9 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 13:23:14 +0800 Subject: [PATCH 08/16] docs: use ut install for local setup --- README.md | 4 ++-- README.zh-CN.md | 4 ++-- vercel.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b4e6ca591..8b63c9eb7 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ export default () => ; Run the local dumi site: ```bash -npm install +ut install npm start ``` @@ -167,7 +167,7 @@ tblRef.current?.scrollTo({ key: 'rowKey', align: 'start' }); ## Development ```bash -npm install +ut install npm start ``` diff --git a/README.zh-CN.md b/README.zh-CN.md index e9a9f762e..6326c1b77 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -59,7 +59,7 @@ export default () =>
; 运行本地 dumi 站点: ```bash -npm install +ut install npm start ``` @@ -167,7 +167,7 @@ tblRef.current?.scrollTo({ key: 'rowKey', align: 'start' }); ## 本地开发 ```bash -npm install +ut install npm start ``` diff --git a/vercel.json b/vercel.json index abcaed321..e9fe94a49 100644 --- a/vercel.json +++ b/vercel.json @@ -1,6 +1,6 @@ { "buildCommand": "npm run build", "outputDirectory": "docs-dist", - "installCommand": "npm install --ignore-scripts --no-audit --loglevel=warn", + "installCommand": "ut install", "framework": null } From ab6e2bcc6ea9541b5e69027d50f58315515404b3 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 13:30:43 +0800 Subject: [PATCH 09/16] chore: restore vercel install command --- vercel.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vercel.json b/vercel.json index e9fe94a49..abcaed321 100644 --- a/vercel.json +++ b/vercel.json @@ -1,6 +1,6 @@ { "buildCommand": "npm run build", "outputDirectory": "docs-dist", - "installCommand": "ut install", + "installCommand": "npm install --ignore-scripts --no-audit --loglevel=warn", "framework": null } From e4123fd3f35695ce818e633d649c5a7d3661efd9 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 14:03:46 +0800 Subject: [PATCH 10/16] chore: align maintenance dependencies --- eslint.config.mjs | 3 +++ package.json | 16 ++++++++-------- react-compat.d.ts | 12 ------------ tsconfig.json | 1 - 4 files changed, 11 insertions(+), 21 deletions(-) delete mode 100644 react-compat.d.ts diff --git a/eslint.config.mjs b/eslint.config.mjs index 7f8ca4ced..76ab8dac2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -36,6 +36,9 @@ function normalizeConfig(config) { if (next.rules) { next.rules = Object.fromEntries( Object.entries(next.rules).filter(([ruleName]) => { + if (ruleName.startsWith('@babel/')) { + return false; + } if (!ruleName.startsWith('@typescript-eslint/')) { return true; } diff --git a/package.json b/package.json index 3a9ca211e..821c4d17d 100644 --- a/package.json +++ b/package.json @@ -76,18 +76,18 @@ "@types/react-dom": "^19.2.3", "@types/responselike": "^1.0.3", "@types/styled-components": "^5.1.36", - "@typescript-eslint/eslint-plugin": "^8.62.0", - "@typescript-eslint/parser": "^8.62.0", + "@typescript-eslint/eslint-plugin": "^8.62.1", + "@typescript-eslint/parser": "^8.62.1", "@umijs/fabric": "^4.0.1", "@vitest/coverage-v8": "^4.1.9", - "dumi": "^2.4.35", + "dumi": "^2.4.38", "eslint": "^9.39.4", "eslint-config-prettier": "^10.1.8", - "eslint-plugin-jest": "^29.15.3", + "eslint-plugin-jest": "^29.15.4", "eslint-plugin-react": "^7.37.5", "eslint-plugin-react-hooks": "^7.1.1", "eslint-plugin-unicorn": "^65.0.1", - "father": "^4.6.23", + "father": "^4.6.24", "gh-pages": "^6.3.0", "glob": "^13.0.6", "husky": "^9.1.7", @@ -95,7 +95,7 @@ "jsdom": "^29.1.1", "less": "^4.6.7", "lint-staged": "^17.0.8", - "prettier": "^3.9.0", + "prettier": "^3.9.4", "react": "^19.2.7", "react-dnd": "^2.5.4", "react-dnd-html5-backend": "^2.5.4", @@ -108,8 +108,8 @@ "vitest": "^4.1.9" }, "peerDependencies": { - "react": ">=18.0.0", - "react-dom": ">=18.0.0" + "react": "^19.2.7", + "react-dom": "^19.2.7" }, "lint-staged": { "*": "prettier --write --ignore-unknown" diff --git a/react-compat.d.ts b/react-compat.d.ts deleted file mode 100644 index c509fe40e..000000000 --- a/react-compat.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react'; - -declare module 'react' { - type ReactText = string | number; - function useRef(): React.MutableRefObject; - function isValidElement

(object: {} | null | undefined): object is React.ReactElement

; - function cloneElement

( - element: React.ReactElement

, - props?: (Partial

& React.Attributes) | null, - ...children: React.ReactNode[] - ): React.ReactElement

; -} diff --git a/tsconfig.json b/tsconfig.json index 09728d378..854b8ec17 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,7 +26,6 @@ "module": "ESNext" }, "include": [ - "react-compat.d.ts", "global.d.ts", ".fatherrc.ts", ".dumirc.ts", From 145f4584ca2a052f83d1ea753b9451bcd0d35ab5 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 14:35:47 +0800 Subject: [PATCH 11/16] fix: preserve React peer dependency range --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 821c4d17d..c9b1cc748 100644 --- a/package.json +++ b/package.json @@ -108,8 +108,8 @@ "vitest": "^4.1.9" }, "peerDependencies": { - "react": "^19.2.7", - "react-dom": "^19.2.7" + "react": ">=18.0.0", + "react-dom": ">=18.0.0" }, "lint-staged": { "*": "prettier --write --ignore-unknown" From 0b453846a24dc39f9b1280953f21b6be289fd3dd Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 18:37:38 +0800 Subject: [PATCH 12/16] docs: use npm install in README --- README.md | 4 ++-- README.zh-CN.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8b63c9eb7..b4e6ca591 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ export default () =>

; Run the local dumi site: ```bash -ut install +npm install npm start ``` @@ -167,7 +167,7 @@ tblRef.current?.scrollTo({ key: 'rowKey', align: 'start' }); ## Development ```bash -ut install +npm install npm start ``` diff --git a/README.zh-CN.md b/README.zh-CN.md index 6326c1b77..e9a9f762e 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -59,7 +59,7 @@ export default () =>
; 运行本地 dumi 站点: ```bash -ut install +npm install npm start ``` @@ -167,7 +167,7 @@ tblRef.current?.scrollTo({ key: 'rowKey', align: 'start' }); ## 本地开发 ```bash -ut install +npm install npm start ``` From 9581f0141a562f7e07f6b407980c59ea3efb74ab Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 18:47:14 +0800 Subject: [PATCH 13/16] chore: remove redundant strict tsconfig flags --- tsconfig.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 854b8ec17..fa82519fa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,13 +16,7 @@ "rc-table/es": ["./src"], "rc-table/es/*": ["./src/*"] }, - "noImplicitAny": false, - "strictNullChecks": false, - "strictPropertyInitialization": false, - "strictFunctionTypes": false, "strict": false, - "noImplicitThis": false, - "strictBindCallApply": false, "module": "ESNext" }, "include": [ From 47ab0612a118e8e5c177add972ce9c33c06dd8e0 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 19:14:02 +0800 Subject: [PATCH 14/16] chore: remove manual global test declarations --- global.d.ts | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/global.d.ts b/global.d.ts index 85e4e4e75..c47834e01 100644 --- a/global.d.ts +++ b/global.d.ts @@ -1,4 +1,5 @@ /// +/// /// /// /// @@ -8,42 +9,4 @@ declare module '*.css'; declare module '*.less'; declare module 'jsonp'; -declare namespace JSX { - type Element = React.JSX.Element; - interface ElementClass extends React.JSX.ElementClass {} - interface ElementAttributesProperty extends React.JSX.ElementAttributesProperty {} - interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {} - type LibraryManagedAttributes = React.JSX.LibraryManagedAttributes; - interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {} - interface IntrinsicClassAttributes extends React.JSX.IntrinsicClassAttributes {} - interface IntrinsicElements extends React.JSX.IntrinsicElements {} -} - -declare namespace jest { - interface Matchers { - lastCalledWith(...expected: unknown[]): R; - nthCalledWith(nthCall: number, ...expected: unknown[]): R; - toBeCalled(): R; - toBeCalledTimes(expected: number): R; - toBeCalledWith(...expected: unknown[]): R; - } -} - -declare const vi: { - fn: any = (...args: any[]) => any>( - implementation?: T, - ) => jest.MockedFunction; - mock: (moduleName: string, factory?: (importOriginal: () => Promise) => unknown) => void; - spyOn: typeof jest.spyOn; - useFakeTimers: () => void; - useRealTimers: () => void; - advanceTimersByTime: (msToRun: number) => void; - clearAllTimers: () => void; - runAllTimers: () => void; - importActual: (moduleName: string) => Promise; - clearAllMocks: () => void; - resetAllMocks: () => void; - restoreAllMocks: () => void; -}; - declare module 'moment/locale/zh-cn'; From e7f0e0273bbc8bd7a67b6a01c278dbfb2070c1af Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 2 Jul 2026 11:54:06 +0800 Subject: [PATCH 15/16] chore: migrate to native eslint flat config --- .eslintrc.js | 23 -------- eslint.config.mjs | 143 +++++++++++++++++++++++++++------------------- package.json | 9 +-- 3 files changed, 85 insertions(+), 90 deletions(-) delete mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 244a44c08..000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,23 +0,0 @@ -const base = require('@umijs/fabric/dist/eslint'); - -module.exports = { - ...base, - rules: { - ...base.rules, - 'arrow-parens': 0, - 'react/no-array-index-key': 0, - 'react/sort-comp': 0, - '@typescript-eslint/no-explicit-any': 1, - '@typescript-eslint/no-empty-interface': 1, - '@typescript-eslint/no-inferrable-types': 0, - 'react/no-find-dom-node': 1, - 'react/require-default-props': 0, - 'no-confusing-arrow': 0, - 'import/no-extraneous-dependencies': 0, - 'import/no-named-as-default-member': 0, - 'import/no-unresolved': 0, - 'jsx-a11y/label-has-for': 0, - 'jsx-a11y/label-has-associated-control': 0, - 'jsx-a11y/control-has-associated-label': 0, - }, -}; diff --git a/eslint.config.mjs b/eslint.config.mjs index 76ab8dac2..d19be2a62 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,56 +1,23 @@ -import { FlatCompat } from '@eslint/eslintrc'; import js from '@eslint/js'; -import tsEslintPlugin from '@typescript-eslint/eslint-plugin'; -import { createRequire } from 'node:module'; -import path from 'node:path'; -import { fileURLToPath } from 'node:url'; +import { defineConfig } from 'eslint/config'; +import prettier from 'eslint-config-prettier'; +import jest from 'eslint-plugin-jest'; +import react from 'eslint-plugin-react'; +import reactHooks from 'eslint-plugin-react-hooks'; +import globals from 'globals'; +import tseslint from 'typescript-eslint'; -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const require = createRequire(import.meta.url); - -const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - allConfig: js.configs.all, -}); - -const recommendedTsRulesConfig = tsEslintPlugin.configs.recommended; -const recommendedTsRulesObject = Array.isArray(recommendedTsRulesConfig) - ? recommendedTsRulesConfig.reduce((rules, config) => ({ ...rules, ...(config.rules || {}) }), {}) - : recommendedTsRulesConfig?.rules || {}; -const recommendedTsRules = new Set(Object.keys(recommendedTsRulesObject)); -const noopRule = { - meta: { type: 'problem', docs: {}, schema: [] }, - create: () => ({}), -}; - -function normalizeConfig(config) { - const next = { ...config }; - - if (next.plugins?.['@typescript-eslint']) { - next.plugins = { ...next.plugins }; - delete next.plugins['@typescript-eslint']; - } - - if (next.rules) { - next.rules = Object.fromEntries( - Object.entries(next.rules).filter(([ruleName]) => { - if (ruleName.startsWith('@babel/')) { - return false; - } - if (!ruleName.startsWith('@typescript-eslint/')) { - return true; - } - return recommendedTsRules.has(ruleName); - }), - ); - } - - return next; -} - -export default [ +export default defineConfig([ + { + plugins: { + '@typescript-eslint': tseslint.plugin, + }, + }, + { + linterOptions: { + reportUnusedDisableDirectives: 'off', + }, + }, { ignores: [ 'node_modules/', @@ -62,27 +29,83 @@ export default [ '.dumi/', '.doc/', '.vercel/', - '.eslintrc.js', 'src/index.d.ts', ], }, { + files: ['**/*.{js,jsx,ts,tsx}'], + extends: [ + js.configs.recommended, + react.configs.flat.recommended, + react.configs.flat['jsx-runtime'], + prettier, + ], plugins: { - '@typescript-eslint': { - ...tsEslintPlugin, - rules: { - ...tsEslintPlugin.rules, - 'consistent-type-exports': noopRule, - }, + 'react-hooks': reactHooks, + }, + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + }, + }, + settings: { + react: { + version: 'detect', }, }, + rules: { + 'no-async-promise-executor': 'off', + 'no-empty-pattern': 'off', + 'no-irregular-whitespace': 'off', + 'no-prototype-builtins': 'off', + 'no-useless-escape': 'off', + 'no-extra-boolean-cast': 'off', + 'no-undef': 'off', + 'no-unused-vars': 'off', + 'react/no-find-dom-node': 'off', + 'react/display-name': 'off', + 'react/no-unknown-property': 'off', + 'react/prop-types': 'off', + 'react-hooks/exhaustive-deps': 'warn', + 'react-hooks/rules-of-hooks': 'error', + }, }, - ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), { + files: ['**/*.{ts,tsx}'], + extends: [...tseslint.configs.recommended], rules: { + '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/no-empty-object-type': 'off', + '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-unsafe-function-type': 'off', + '@typescript-eslint/no-unnecessary-type-constraint': 'off', '@typescript-eslint/no-unused-vars': 'off', }, }, -]; + { + files: ['src/**/*.{ts,tsx}'], + languageOptions: { + parserOptions: { + projectService: true, + tsconfigRootDir: import.meta.dirname, + }, + }, + }, + { + files: ['tests/**/*.{js,jsx,ts,tsx}', '**/*.{test,spec}.{js,jsx,ts,tsx}'], + extends: [jest.configs['flat/recommended']], + rules: { + 'jest/no-disabled-tests': 'off', + 'jest/no-done-callback': 'off', + 'jest/no-identical-title': 'off', + 'jest/expect-expect': 'off', + 'jest/no-alias-methods': 'off', + 'jest/no-conditional-expect': 'off', + 'jest/no-export': 'off', + 'jest/no-standalone-expect': 'off', + 'jest/valid-expect': 'off', + 'jest/valid-title': 'off', + }, + }, +]); diff --git a/package.json b/package.json index c9b1cc748..69e9fbbed 100644 --- a/package.json +++ b/package.json @@ -57,9 +57,6 @@ "clsx": "^2.1.1" }, "devDependencies": { - "@babel/eslint-parser": "^7.29.7", - "@babel/eslint-plugin": "^7.29.7", - "@eslint/eslintrc": "^3.3.5", "@eslint/js": "^9.39.4", "@rc-component/dropdown": "^1.0.2", "@rc-component/father-plugin": "^2.2.0", @@ -76,9 +73,6 @@ "@types/react-dom": "^19.2.3", "@types/responselike": "^1.0.3", "@types/styled-components": "^5.1.36", - "@typescript-eslint/eslint-plugin": "^8.62.1", - "@typescript-eslint/parser": "^8.62.1", - "@umijs/fabric": "^4.0.1", "@vitest/coverage-v8": "^4.1.9", "dumi": "^2.4.38", "eslint": "^9.39.4", @@ -86,10 +80,10 @@ "eslint-plugin-jest": "^29.15.4", "eslint-plugin-react": "^7.37.5", "eslint-plugin-react-hooks": "^7.1.1", - "eslint-plugin-unicorn": "^65.0.1", "father": "^4.6.24", "gh-pages": "^6.3.0", "glob": "^13.0.6", + "globals": "^17.7.0", "husky": "^9.1.7", "immutability-helper": "^3.0.0", "jsdom": "^29.1.1", @@ -105,6 +99,7 @@ "regenerator-runtime": "^0.14.0", "styled-components": "^6.1.1", "typescript": "^6.0.3", + "typescript-eslint": "^8.62.1", "vitest": "^4.1.9" }, "peerDependencies": { From 24ccbb4a8fef0ec73d42f2387f6d27b402c371fe Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 3 Jul 2026 10:58:13 +0800 Subject: [PATCH 16/16] chore: address review comments --- eslint.config.mjs | 10 +++++++--- package.json | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index d19be2a62..40f08ec94 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,5 +1,7 @@ import js from '@eslint/js'; import { defineConfig } from 'eslint/config'; +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; import prettier from 'eslint-config-prettier'; import jest from 'eslint-plugin-jest'; import react from 'eslint-plugin-react'; @@ -7,6 +9,8 @@ import reactHooks from 'eslint-plugin-react-hooks'; import globals from 'globals'; import tseslint from 'typescript-eslint'; +const tsconfigRootDir = dirname(fileURLToPath(import.meta.url)); + export default defineConfig([ { plugins: { @@ -15,7 +19,7 @@ export default defineConfig([ }, { linterOptions: { - reportUnusedDisableDirectives: 'off', + reportUnusedDisableDirectives: 'warn', }, }, { @@ -26,10 +30,10 @@ export default defineConfig([ 'lib/', 'dist/', 'docs-dist/', + '.docs-dist/', '.dumi/', '.doc/', '.vercel/', - 'src/index.d.ts', ], }, { @@ -88,7 +92,7 @@ export default defineConfig([ languageOptions: { parserOptions: { projectService: true, - tsconfigRootDir: import.meta.dirname, + tsconfigRootDir, }, }, }, diff --git a/package.json b/package.json index 69e9fbbed..d00a427d3 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,6 @@ "@testing-library/dom": "^10.4.1", "@testing-library/jest-dom": "^6.9.1", "@testing-library/react": "^16.3.2", - "@types/jest": "^30.0.0", "@types/node": "^26.0.1", "@types/react": "^19.2.17", "@types/react-dom": "^19.2.3",