eslint.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import js from '@eslint/js';
  2. import typescriptEslint from '@typescript-eslint/eslint-plugin';
  3. import typescriptParser from '@typescript-eslint/parser';
  4. import reactPlugin from 'eslint-plugin-react';
  5. import reactHooks from 'eslint-plugin-react-hooks';
  6. import globals from 'globals';
  7. export default [
  8. // 基础配置
  9. {
  10. files: ['**/*.{js,jsx,ts,tsx}'],
  11. ignores: [
  12. 'dist/**',
  13. 'node_modules/**',
  14. '*.config.js',
  15. '*.config.ts',
  16. 'tests/e2e/**',
  17. 'scripts/**',
  18. 'server.js',
  19. 'vitest.config.components.ts',
  20. 'coverage/**',
  21. ],
  22. languageOptions: {
  23. ecmaVersion: 'latest',
  24. sourceType: 'module',
  25. parser: typescriptParser,
  26. parserOptions: {
  27. ecmaFeatures: {
  28. jsx: true,
  29. },
  30. },
  31. globals: {
  32. ...globals.browser,
  33. ...globals.es2021,
  34. RequestInfo: 'readonly',
  35. RequestInit: 'readonly',
  36. URL: 'readonly',
  37. Response: 'readonly',
  38. },
  39. },
  40. plugins: {
  41. '@typescript-eslint': typescriptEslint,
  42. react: reactPlugin,
  43. 'react-hooks': reactHooks,
  44. },
  45. rules: {
  46. // 基础ESLint规则
  47. ...js.configs.recommended.rules,
  48. // TypeScript规则
  49. '@typescript-eslint/no-unused-vars': ['error', {
  50. argsIgnorePattern: '^_',
  51. varsIgnorePattern: '^_',
  52. caughtErrorsIgnorePattern: '^_',
  53. }],
  54. '@typescript-eslint/no-explicit-any': 'warn',
  55. '@typescript-eslint/explicit-function-return-type': 'off',
  56. // React规则
  57. 'react/react-in-jsx-scope': 'off',
  58. 'react/prop-types': 'off',
  59. // 通用规则
  60. 'no-console': 'warn',
  61. 'prefer-const': 'error',
  62. 'no-undef': 'off', // TypeScript已经处理了未定义变量
  63. 'no-unused-vars': 'off', // 使用TypeScript的版本
  64. },
  65. settings: {
  66. react: {
  67. version: 'detect',
  68. },
  69. },
  70. },
  71. // Node.js环境配置
  72. {
  73. files: ['src/server/**/*.{js,ts}', 'src/test/**/*.{js,ts}'],
  74. languageOptions: {
  75. globals: {
  76. ...globals.node,
  77. },
  78. },
  79. },
  80. // 测试环境配置
  81. {
  82. files: ['src/**/__tests__/**/*.{js,ts,jsx,tsx}', 'src/**/__integration_tests__/**/*.{js,ts,jsx,tsx}'],
  83. languageOptions: {
  84. globals: {
  85. ...globals.jest,
  86. vi: 'readonly',
  87. },
  88. },
  89. },
  90. ];