module.exports = { root: true, /* 环境配置 */ env: { browser: true, es2021: true, node: true, }, /* 扩展配置 */ extends: [ 'react-app', // Create React App 默认规则 'react-app/jest', // Jest 测试规则 'eslint:recommended', // ESLint 推荐规则 'plugin:react/recommended', // React 推荐规则 'plugin:react-hooks/recommended', // React Hooks 规则 'plugin:prettier/recommended', // Prettier 集成 ], /* 解析器选项 */ parserOptions: { ecmaVersion: 'latest', sourceType: 'module', ecmaFeatures: { jsx: true, }, }, /* 插件 */ plugins: ['react', 'react-hooks', 'prettier'], /* 规则配置 */ rules: { // React 'react/react-in-jsx-scope': 'off', // React 17+ 不需要导入 React 'react/prop-types': 'off', // 使用 TypeScript 类型检查,不需要 PropTypes 'react/display-name': 'off', // 允许匿名组件 // 通用 'no-console': ['warn', { allow: ['warn', 'error'] }], // 仅警告 console.log 'no-unused-vars': ['warn', { argsIgnorePattern: '^_', // 忽略以 _ 开头的未使用参数 varsIgnorePattern: '^_', // 忽略以 _ 开头的未使用变量 }], 'prettier/prettier': ['warn', {}, { usePrettierrc: true }], // 使用项目的 Prettier 配置 }, /* 设置 */ settings: { react: { version: 'detect', // 自动检测 React 版本 }, }, /* TypeScript 文件特殊配置 */ // 注意:react-app 已包含完整的 @typescript-eslint 配置 // 此处仅覆盖特定规则,不重复加载插件 overrides: [ { files: ['**/*.ts', '**/*.tsx'], rules: { // TypeScript 特定规则覆盖 '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', }], '@typescript-eslint/no-non-null-assertion': 'warn', 'no-unused-vars': 'off', }, }, // Company 视图主题硬编码检测 { files: ['src/views/Company/**/*.{ts,tsx,js,jsx}'], excludedFiles: ['**/theme/**', '**/*.test.*', '**/*.spec.*'], plugins: ['local-rules'], rules: { // warning 级别:提醒开发者但不阻塞构建 'local-rules/no-hardcoded-fui-colors': 'warn', }, }, ], /* 忽略文件(与 .eslintignore 等效)*/ ignorePatterns: [ 'node_modules/', 'build/', 'dist/', '*.config.js', 'public/mockServiceWorker.js', ], };