eslint.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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': [
  22. 'error',
  23. {
  24. singleAttributePerLine: false,
  25. htmlWhitespaceSensitivity: 'ignore'
  26. }
  27. ],
  28. // 基础规则
  29. 'no-console': ['warn', { allow: ['warn', 'error'] }], // 允许 console.warn 和 console.error
  30. semi: 'off', // 语句末尾分号
  31. 'no-var': 'error',
  32. 'prefer-const': 'error', // 优先使用 const
  33. 'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], // 未使用的变量警告
  34. // Vue 相关规则
  35. 'vue/multi-word-component-names': 'off', // 关闭组件名必须多词的限制
  36. 'vue/no-v-html': 'warn', // 使用 v-html 有 XSS 风险,仅警告
  37. 'vue/require-default-prop': 'error', // Props 需要默认值
  38. // 移动端性能相关
  39. 'vue/no-async-in-computed-properties': 'error', // 计算属性中不应有异步操作
  40. 'vue/no-side-effects-in-computed-properties': 'error', // 计算属性中不应有副作用
  41. // 格式化相关
  42. 'vue/html-indent': ['error', 2], // HTML 缩进 2 个空格
  43. 'vue/html-closing-bracket-newline': [
  44. 'error',
  45. {
  46. // 标签闭合括号换行规则
  47. singleline: 'never',
  48. multiline: 'always'
  49. }
  50. ]
  51. }
  52. }
  53. ]