eslint.config.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import prettierPlugin from 'eslint-plugin-prettier'
  2. import typescriptPlugin from '@typescript-eslint/eslint-plugin'
  3. import typescriptParser from '@typescript-eslint/parser'
  4. export default [
  5. {
  6. files: [
  7. '**/*.ts',
  8. '**/*.mts',
  9. ], // 指定文件类型
  10. languageOptions: {
  11. ecmaVersion: 2020, // 使用 ECMAScript 2020 语法
  12. sourceType: 'module',
  13. parser:
  14. typescriptParser,
  15. parserOptions: {
  16. project:
  17. './tsconfig.json', // 指定 TypeScript 配置文件
  18. },
  19. },
  20. plugins: {
  21. '@typescript-eslint':
  22. typescriptPlugin,
  23. prettier:
  24. prettierPlugin,
  25. },
  26. rules: {
  27. // Prettier 配置规则
  28. 'prettier/prettier': [
  29. 'error',
  30. {},
  31. {
  32. usePrettierrc: true, // 读取 .prettierrc 配置
  33. },
  34. ],
  35. // TypeScript 规则
  36. '@typescript-eslint/no-inferrable-types':
  37. 'off',
  38. '@typescript-eslint/no-unused-vars':
  39. 'warn',
  40. '@typescript-eslint/no-var-requires':
  41. 'off',
  42. '@typescript-eslint/no-explicit-any':
  43. 'off',
  44. // 关闭 unused-vars 的基础规则(避免冲突)
  45. 'no-unused-vars': 'off',
  46. },
  47. ignores: [
  48. // 替代 .eslintignore 的配置
  49. 'node_modules',
  50. 'dist/',
  51. '*.log',
  52. '/**/*.js',
  53. ],
  54. },
  55. ]