eslint.config.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import antfu from '@antfu/eslint-config'
  2. import pluginVitest from '@vitest/eslint-plugin'
  3. import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
  4. import pluginPlaywright from 'eslint-plugin-playwright'
  5. import pluginVue from 'eslint-plugin-vue'
  6. // To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
  7. // import { configureVueProject } from '@vue/eslint-config-typescript'
  8. // configureVueProject({ scriptLangs: ['ts', 'tsx'] })
  9. // More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup
  10. export default antfu(
  11. {
  12. type: 'app',
  13. vue: true, // 启用 Vue 支持
  14. typescript: true, // 启用 TS 支持
  15. jsonc: true, // 支持 .json/.jsonc
  16. yaml: true, // 支持 .yaml
  17. markdown: true, // 支持 .md 中代码块
  18. unocss: true, // 支持 unocss
  19. test: true, // 启用 Vitest 支持
  20. stylistic: {
  21. indent: 2,
  22. semi: false,
  23. quotes: 'single',
  24. jsx: true,
  25. },
  26. ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
  27. rules: {
  28. // 禁用规则
  29. 'perfectionist/sort-imports': 'off',
  30. 'perfectionist/sort-named-imports': 'off',
  31. 'perfectionist/sort-named-exports': 'off',
  32. 'vue/block-order': 'off',
  33. 'node/prefer-global/process': 'off',
  34. 'import/consistent-type-specifier-style': 'off',
  35. 'antfu/top-level-function': 'off',
  36. 'antfu/if-newline': 'off',
  37. 'ts/no-use-before-define': 'off',
  38. 'dot-notation': 'off',
  39. // 开发期禁用规则
  40. 'no-console': 'off',
  41. },
  42. },
  43. pluginVue.configs['flat/essential'],
  44. {
  45. rules: {
  46. // ✅ 添加 vue/block-lang 规则
  47. 'vue/block-lang': [
  48. 'error',
  49. {
  50. script: {
  51. lang: ['ts', 'tsx'], // ✅ 支持 tsx
  52. },
  53. },
  54. ],
  55. // 禁用 pluginVue.configs['flat/essential'] 开启的规则
  56. 'vue/multi-word-component-names': 'off', // 🚫 禁用多单词组件名规则
  57. },
  58. },
  59. // ✅ 测试文件配置
  60. {
  61. ...pluginVitest.configs.recommended,
  62. files: ['src/**/__tests__/*'],
  63. },
  64. // ✅ Playwright 配置
  65. {
  66. ...pluginPlaywright.configs['flat/recommended'],
  67. files: ['e2e/**/*.{test,spec}.{js,ts,jsx,tsx}'],
  68. },
  69. skipFormatting,
  70. )