eslint.config.mjs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. rules: {
  18. '@typescript-eslint/ban-ts-comment': 'off', // 彻底关闭 ts-comment 警告
  19. }
  20. },
  21. globalIgnores([
  22. // 构建输出
  23. '**/dist/**',
  24. '**/dist-ssr/**',
  25. '**/coverage/**',
  26. // 依赖
  27. '**/node_modules/**',
  28. // Git相关
  29. '**/.git/**',
  30. // 缓存目录
  31. '**/.cache/**',
  32. '**/.temp/**',
  33. '**/.eslintcache',
  34. // 编辑器目录和文件
  35. '**/.vscode/**',
  36. '**/.idea/**',
  37. '**/*.suo',
  38. '**/*.ntvs*',
  39. '**/*.njsproj',
  40. '**/*.sln',
  41. '**/*.sw?',
  42. // 配置文件
  43. '**/*.config.js',
  44. '**/*.config.ts',
  45. '**/*.config.mjs',
  46. '**/*.config.cjs',
  47. '**/rspack.*.js',
  48. '**/rspack.*.ts',
  49. '**/vite.*.js',
  50. '**/vite.*.ts',
  51. // 环境文件
  52. '**/.env*',
  53. '!**/.env.example',
  54. // 包管理器文件
  55. '**/pnpm-lock.yaml',
  56. '**/package-lock.json',
  57. '**/yarn.lock',
  58. // 历史文件
  59. '**/.history/**',
  60. // 日志文件
  61. '**/*.log',
  62. '**/npm-debug.log*',
  63. '**/yarn-debug.log*',
  64. '**/yarn-error.log*',
  65. '**/pnpm-debug.log*',
  66. // 系统文件
  67. '**/.DS_Store',
  68. '**/Thumbs.db'
  69. ]),
  70. {
  71. languageOptions: {
  72. globals: {
  73. ...globals.browser,
  74. ...globals.node,
  75. // 添加全局变量
  76. defineOptions: 'readonly', // 允许使用 defineOptions
  77. },
  78. parserOptions: {
  79. ecmaFeatures: {
  80. jsx: true
  81. }
  82. }
  83. },
  84. linterOptions: {
  85. reportUnusedDisableDirectives: false
  86. }
  87. },
  88. // Vue规则配置
  89. pluginVue.configs['flat/essential'],
  90. pluginVue.configs['flat/strongly-recommended'],
  91. eslintConfigPrettier,
  92. {
  93. rules: {
  94. // 禁用烦人的 ts-comment 警告
  95. '@typescript-eslint/ban-ts-comment': 'off',
  96. // Vue特定规则
  97. 'vue/multi-word-component-names': 'off', // 关闭组件名必须是多词的规则
  98. 'vue/no-unused-vars': 'off', // 关闭未使用变量的警告
  99. 'vue/html-self-closing': ['warn', {
  100. html: {
  101. void: 'always',
  102. normal: 'always',
  103. component: 'always'
  104. }
  105. }],
  106. 'vue/max-attributes-per-line': 'off', // 关闭每行最大属性数量限制
  107. // 通用规则
  108. 'no-console': 'off', // 关闭控制台语句的警告
  109. 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  110. '@typescript-eslint/no-require-imports': 'off', // 允许 require 导入
  111. }
  112. },
  113. // TypeScript规则配置
  114. vueTsConfigs.recommended,
  115. {
  116. rules: {
  117. '@typescript-eslint/ban-ts-comment': 'off', // 彻底关闭 ts-comment 警告
  118. '@typescript-eslint/explicit-function-return-type': 'off',
  119. '@typescript-eslint/explicit-module-boundary-types': 'off',
  120. '@typescript-eslint/no-explicit-any': 'off', // 关闭 any 类型的警告
  121. '@typescript-eslint/no-unused-vars': 'off', // 关闭未使用变量的警告
  122. }
  123. },
  124. );