eslint.config.mjs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/first-attribute-linebreak': 'off', // 关闭属性换行规则
  99. 'vue/no-unused-vars': 'off', // 关闭未使用变量的警告
  100. 'vue/html-self-closing': 'off', // 关闭要求HTML元素自闭合的规则
  101. 'vue/max-attributes-per-line': 'off', // 关闭每行最大属性数量限制
  102. 'vue/require-default-prop': 'off', // 关闭props必须有默认值的要求
  103. 'vue/attribute-hyphenation': 'off', // 关闭属性必须使用连字符的要求
  104. 'vue/no-reserved-component-names': 'off', // 关闭组件名称限制(允许使用Dialog等HTML保留名称)
  105. 'vue/operator-linebreak': 'off',
  106. 'vue/singleline-html-element-content-newline': 'off',
  107. 'vue/no-v-model-argument': 'off',
  108. 'vue/require-prop-types': 'off',
  109. 'vue/quote-props': 'off',
  110. 'vue/no-irregular-whitespace': 'off',
  111. 'vue/prop-name-casing': 'off',
  112. 'vue/html-indent': 'off',
  113. // 通用规则
  114. 'no-console': 'off', // 关闭控制台语句的警告
  115. 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  116. '@typescript-eslint/no-require-imports': 'off', // 允许 require 导入
  117. '@typescript-eslint/ban-ts-comment': 'off', // 完全关闭 ts-comment 警告
  118. 'prefer-const': 'warn', // 将never reassigned的let改为warning而不是error
  119. '@typescript-eslint/no-unused-expressions': [
  120. 'error',
  121. {
  122. allowShortCircuit: true,
  123. allowTernary: false,
  124. allowTaggedTemplates: false,
  125. },
  126. ],
  127. },
  128. },
  129. // TypeScript规则配置
  130. vueTsConfigs.recommended,
  131. {
  132. rules: {
  133. '@typescript-eslint/ban-ts-comment': 'off', // 彻底关闭 ts-comment 警告
  134. '@typescript-eslint/explicit-function-return-type': 'off',
  135. '@typescript-eslint/explicit-module-boundary-types': 'off',
  136. '@typescript-eslint/no-explicit-any': 'off', // 关闭 any 类型的警告
  137. '@typescript-eslint/no-unused-vars': 'off', // 关闭未使用变量的警告
  138. '@typescript-eslint/no-unsafe-function-type': 'off', // 关闭Function类型警告
  139. },
  140. },
  141. );