eslint.config.mjs 3.0 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. }
  74. },
  75. // Vue规则配置
  76. pluginVue.configs['flat/essential'],
  77. pluginVue.configs['flat/strongly-recommended'],
  78. eslintConfigPrettier,
  79. {
  80. rules: {
  81. // Vue特定规则
  82. 'vue/multi-word-component-names': 'warn',
  83. 'vue/no-unused-vars': 'warn',
  84. 'vue/html-self-closing': ['warn', {
  85. html: {
  86. void: 'always',
  87. normal: 'always',
  88. component: 'always'
  89. }
  90. }],
  91. 'vue/max-attributes-per-line': ['warn', {
  92. singleline: 3,
  93. multiline: 1
  94. }],
  95. // 通用规则
  96. 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  97. 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  98. '@typescript-eslint/no-require-imports': 'error',
  99. }
  100. },
  101. // TypeScript规则配置
  102. vueTsConfigs.recommended,
  103. {
  104. rules: {
  105. '@typescript-eslint/explicit-function-return-type': 'off',
  106. '@typescript-eslint/explicit-module-boundary-types': 'off',
  107. '@typescript-eslint/no-explicit-any': 'warn',
  108. '@typescript-eslint/no-unused-vars': ['warn', {
  109. argsIgnorePattern: '^_',
  110. varsIgnorePattern: '^_'
  111. }],
  112. }
  113. },
  114. );