eslint.config.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import js from '@eslint/js';
  2. import globals from 'globals';
  3. import reactHooks from 'eslint-plugin-react-hooks';
  4. import reactRefresh from 'eslint-plugin-react-refresh';
  5. import tseslint from 'typescript-eslint';
  6. import react from 'eslint-plugin-react';
  7. import importPlugin from 'eslint-plugin-import';
  8. import jsxA11y from 'eslint-plugin-jsx-a11y';
  9. import prettierConfig from 'eslint-config-prettier/flat';
  10. export default [
  11. { ignores: ['dist/**/*', 'node_modules/**/*', 'public/**/*'] },
  12. js.configs.recommended,
  13. ...tseslint.configs.recommended,
  14. {
  15. files: ['**/*.{ts,tsx}'],
  16. languageOptions: {
  17. ecmaVersion: 2020,
  18. globals: {
  19. ...globals.browser,
  20. ...globals.node,
  21. Recordable: 'readonly',
  22. ImportMetaEnv: 'readonly',
  23. BuildCompression: 'readonly',
  24. },
  25. parser: tseslint.parser,
  26. parserOptions: {
  27. ecmaFeatures: {
  28. jsx: true,
  29. },
  30. sourceType: 'module',
  31. project: ['./tsconfig.json'],
  32. tsconfigRootDir: '.',
  33. },
  34. },
  35. plugins: {
  36. 'react-hooks': reactHooks,
  37. 'react-refresh': reactRefresh,
  38. react: react,
  39. import: importPlugin,
  40. 'jsx-a11y': jsxA11y,
  41. '@typescript-eslint': tseslint.plugin,
  42. },
  43. rules: {
  44. ...reactHooks.configs.recommended.rules,
  45. 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
  46. 'react/react-in-jsx-scope': 'off',
  47. 'react/prop-types': 'off',
  48. '@typescript-eslint/explicit-module-boundary-types': 'off',
  49. '@typescript-eslint/no-explicit-any': 'off',
  50. '@typescript-eslint/no-unused-vars': [
  51. 'warn',
  52. {
  53. argsIgnorePattern: '^_',
  54. varsIgnorePattern: '^_',
  55. ignoreRestSiblings: true,
  56. },
  57. ],
  58. 'import/order': [
  59. 'error',
  60. {
  61. groups: [
  62. 'builtin',
  63. 'external',
  64. 'internal',
  65. 'parent',
  66. 'sibling',
  67. 'index',
  68. 'object',
  69. 'type',
  70. ],
  71. pathGroups: [
  72. {
  73. pattern: 'react',
  74. group: 'external',
  75. position: 'before',
  76. },
  77. {
  78. pattern: '@/**',
  79. group: 'internal',
  80. position: 'before',
  81. },
  82. ],
  83. pathGroupsExcludedImportTypes: ['react'],
  84. 'newlines-between': 'always',
  85. alphabetize: {
  86. order: 'asc',
  87. caseInsensitive: true,
  88. },
  89. distinctGroup: true,
  90. },
  91. ],
  92. // 移除 indent 规则,让 Prettier 处理缩进
  93. // indent 规则与 Prettier 冲突,已由 eslint-config-prettier 禁用
  94. 'no-unused-vars': 'off',
  95. 'no-redeclare': 'off',
  96. 'prefer-const': 'error',
  97. },
  98. settings: {
  99. react: {
  100. version: 'detect',
  101. },
  102. 'import/resolver': {
  103. typescript: {
  104. project: ['./tsconfig.json'],
  105. },
  106. },
  107. },
  108. },
  109. // 禁用所有与 Prettier 冲突的 ESLint 规则
  110. // eslint-config-prettier 必须在配置数组的最后,以覆盖其他配置
  111. prettierConfig,
  112. ];