From d52630ab76eda7ab9bc6e9a94d23c7637848f2cb Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 8 Nov 2024 09:22:51 +0800 Subject: [PATCH] refactor(core): improve ESLint and TypeScript config Update the ESLint configuration to include the ES2022 environment and add support for *.tsx files. Integrate React plugin and adjust parser options to handle JSX and include a project reference to tsconfig.json. Relax TypeScript rules for explicit function return types and any usage. Additionally, refactor the BeSelect component to use a more specific props interface and clean up the usage of Radix UI components. --- web/core/.eslintrc.cjs | 19 ++++++++++++--- web/core/lib/editor/components/ui-select.tsx | 25 +++++++++++++------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/web/core/.eslintrc.cjs b/web/core/.eslintrc.cjs index cd673bc..5d03c0d 100644 --- a/web/core/.eslintrc.cjs +++ b/web/core/.eslintrc.cjs @@ -5,7 +5,8 @@ module.exports = defineConfig({ root: true, env: { node: true, - browser: true + browser: true, + es2022: true }, extends: [ 'eslint:recommended', @@ -18,23 +19,35 @@ module.exports = defineConfig({ ignorePatterns: ['dist', 'dist-types'], overrides: [ { + files: ['*.ts', '*.tsx'], // Added *.tsx extends: [ 'eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react-hooks/recommended', + 'plugin:react/recommended' // Added React plugin ], - plugins: ['@typescript-eslint', 'import', 'react-refresh'], + plugins: ['@typescript-eslint', 'import', 'react-refresh', 'react'], parser: '@typescript-eslint/parser', parserOptions: { ecmaVersion: 'latest', sourceType: 'module', + ecmaFeatures: { + jsx: true + }, + project: './tsconfig.json' // Add reference to your tsconfig + }, + settings: { + react: { + version: 'detect' + } }, - files: ['*.ts'], rules: { 'react-refresh/only-export-components': [ 'warn', { allowConstantExport: true }, ], + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/no-explicit-any': 'off' }, }, { diff --git a/web/core/lib/editor/components/ui-select.tsx b/web/core/lib/editor/components/ui-select.tsx index cbe92e5..99d70d7 100644 --- a/web/core/lib/editor/components/ui-select.tsx +++ b/web/core/lib/editor/components/ui-select.tsx @@ -6,24 +6,31 @@ import { ChevronUpIcon, } from '@radix-ui/react-icons'; -export const BeSelect: React.FC = React.forwardRef( - ({ children, ...props }, forwardedRef) => { +interface BeSelectProps { + children: React.ReactNode; + [key: string]: any; +} + +export const BeSelect = React.forwardRef( + (props, forwardedRef) => { + const { children, ...rest } = props; + return ( - - - - - + + + + + - + {children} - +