eslint.config.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import globals from 'globals'
  2. import pluginJs from '@eslint/js'
  3. import pluginVue from 'eslint-plugin-vue'
  4. import prettier from 'eslint-plugin-prettier'
  5. import eslintConfigPrettier from 'eslint-config-prettier'
  6. /** @type {import('eslint').Linter.Config[]} */
  7. export default [
  8. { ignores: ['node_modules', 'dist'] },
  9. { files: ['**/*.{js,mjs,cjs,vue}'] },
  10. { languageOptions: { globals: { ...globals.browser, ...globals.node } } },
  11. pluginJs.configs.recommended,
  12. ...pluginVue.configs['flat/essential'],
  13. ...pluginVue.configs['flat/strongly-recommended'],
  14. eslintConfigPrettier,
  15. {
  16. plugins: {
  17. prettier
  18. },
  19. rules: {
  20. // 添加 prettier 规则
  21. 'prettier/prettier': 'error',
  22. // 基础规则
  23. 'no-console': ['warn', { allow: ['warn', 'error'] }], // 允许 console.warn 和 console.error
  24. semi: 'off', // 语句末尾分号
  25. 'no-var': 'error',
  26. 'prefer-const': 'error', // 优先使用 const
  27. 'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], // 未使用的变量警告
  28. // Vue 相关规则
  29. 'vue/multi-word-component-names': 'off', // 关闭组件名必须多词的限制
  30. 'vue/no-v-html': 'warn', // 使用 v-html 有 XSS 风险,仅警告
  31. 'vue/require-default-prop': 'error', // Props 需要默认值
  32. // 移动端性能相关
  33. 'vue/no-async-in-computed-properties': 'error', // 计算属性中不应有异步操作
  34. 'vue/no-side-effects-in-computed-properties': 'error', // 计算属性中不应有副作用
  35. // 格式化相关
  36. 'vue/html-indent': ['error', 2], // HTML 缩进 2 个空格
  37. 'vue/html-closing-bracket-newline': [
  38. 'error',
  39. {
  40. // 标签闭合括号换行规则
  41. singleline: 'never',
  42. multiline: 'always'
  43. }
  44. ]
  45. }
  46. }
  47. ]