import js from '@eslint/js'; import tseslint from 'typescript-eslint'; import reactHooks from 'eslint-plugin-react-hooks'; import reactRefresh from 'eslint-plugin-react-refresh'; import globals from 'globals'; export default tseslint.config( // 全局忽略 { ignores: ['dist/**', 'node_modules/**', 'coverage/**'], }, // 基础推荐规则 js.configs.recommended, ...tseslint.configs.recommended, { files: ['src/**/*.{ts,tsx}'], languageOptions: { ecmaVersion: 2022, globals: globals.browser, }, plugins: { 'react-hooks': reactHooks, 'react-refresh': reactRefresh, }, rules: { // React Hooks 规则升级为 error(这是真正的 bug 来源) ...reactHooks.configs.recommended.rules, 'react-refresh/only-export-components': [ 'warn', { allowConstantExport: true }, ], // 渐进式策略:TypeScript 推荐规则默认 warn,不阻断 // 仅把最关键的几个升级为 error '@typescript-eslint/no-unused-vars': [ 'error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', // catch (_) 是"故意忽略错误"的惯用法,单独配置项控制 caughtErrorsIgnorePattern: '^_', }, ], '@typescript-eslint/no-explicit-any': 'warn', // no-console 在测试环境外保留 console 'no-console': ['warn', { allow: ['warn', 'error'] }], }, }, // 测试文件放宽规则 { files: ['src/**/*.test.{ts,tsx}', 'src/test/**'], rules: { '@typescript-eslint/no-explicit-any': 'off', 'no-console': 'off', }, }, );