eslint.config.mjs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import {
  2. defineConfigWithVueTs,
  3. vueTsConfigs,
  4. } from '@vue/eslint-config-typescript';
  5. import pluginVue from 'eslint-plugin-vue';
  6. import { globalIgnores } from 'eslint/config';
  7. import globals from 'globals';
  8. import eslintConfigPrettier from 'eslint-config-prettier';
  9. // To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
  10. // import { configureVueProject } from '@vue/eslint-config-typescript'
  11. // configureVueProject({ scriptLangs: ['ts', 'tsx'] })
  12. // More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup
  13. export default defineConfigWithVueTs(
  14. {
  15. name: 'app/files-to-lint',
  16. files: ['**/*.{ts,mts,tsx,vue}'],
  17. },
  18. globalIgnores([
  19. // 构建输出
  20. '**/dist/**',
  21. '**/dist-ssr/**',
  22. '**/coverage/**',
  23. // 依赖
  24. '**/node_modules/**',
  25. // Git相关
  26. '**/.git/**',
  27. // 缓存目录
  28. '**/.cache/**',
  29. '**/.temp/**',
  30. '**/.eslintcache',
  31. // 编辑器目录和文件
  32. '**/.vscode/**',
  33. '**/.idea/**',
  34. '**/*.suo',
  35. '**/*.ntvs*',
  36. '**/*.njsproj',
  37. '**/*.sln',
  38. '**/*.sw?',
  39. // 配置文件
  40. '**/*.config.js',
  41. '**/*.config.ts',
  42. '**/*.config.mjs',
  43. '**/*.config.cjs',
  44. '**/rspack.*.js',
  45. '**/rspack.*.ts',
  46. '**/vite.*.js',
  47. '**/vite.*.ts',
  48. // 环境文件
  49. '**/.env*',
  50. '!**/.env.example',
  51. // 包管理器文件
  52. '**/pnpm-lock.yaml',
  53. '**/package-lock.json',
  54. '**/yarn.lock',
  55. // 历史文件
  56. '**/.history/**',
  57. // 日志文件
  58. '**/*.log',
  59. '**/npm-debug.log*',
  60. '**/yarn-debug.log*',
  61. '**/yarn-error.log*',
  62. '**/pnpm-debug.log*',
  63. // 系统文件
  64. '**/.DS_Store',
  65. '**/Thumbs.db'
  66. ]),
  67. {
  68. languageOptions: {
  69. globals: {
  70. ...globals.browser,
  71. ...globals.node,
  72. // 添加全局变量
  73. defineOptions: 'readonly', // 允许使用 defineOptions
  74. }
  75. }
  76. },
  77. // Vue规则配置
  78. pluginVue.configs['flat/essential'],
  79. pluginVue.configs['flat/strongly-recommended'],
  80. eslintConfigPrettier,
  81. {
  82. rules: {
  83. // Vue特定规则
  84. 'vue/multi-word-component-names': 'off', // 关闭组件名必须是多词的规则
  85. 'vue/no-unused-vars': 'off', // 关闭未使用变量的警告
  86. 'vue/html-self-closing': ['warn', {
  87. html: {
  88. void: 'always',
  89. normal: 'always',
  90. component: 'always'
  91. }
  92. }],
  93. 'vue/max-attributes-per-line': ['warn', {
  94. singleline: 3,
  95. multiline: 1
  96. }],
  97. // 通用规则
  98. 'no-console': 'off', // 关闭控制台语句的警告
  99. 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  100. '@typescript-eslint/no-require-imports': 'off', // 允许 require 导入
  101. '@typescript-eslint/ban-ts-comment': 'off', // 关闭 ts-comment 警告
  102. }
  103. },
  104. // TypeScript规则配置
  105. vueTsConfigs.recommended,
  106. {
  107. rules: {
  108. '@typescript-eslint/explicit-function-return-type': 'off',
  109. '@typescript-eslint/explicit-module-boundary-types': 'off',
  110. '@typescript-eslint/no-explicit-any': 'off', // 关闭 any 类型的警告
  111. '@typescript-eslint/no-unused-vars': 'off', // 关闭未使用变量的警告
  112. }
  113. },
  114. );