.eslintrc.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module.exports = {
  2. root: true,
  3. env: {
  4. node: true,
  5. browser: true,
  6. es6: true
  7. },
  8. // 扩展规则
  9. extends: [
  10. 'plugin:vue/essential', // Vue 2 核心规则
  11. 'eslint:recommended', // ESLint 推荐规则
  12. 'plugin:prettier/recommended' // 整合 Prettier,使其作为 ESLint 规则运行
  13. ],
  14. parserOptions: {
  15. parser: '@babel/eslint-parser', // 使用 babel 解析器支持最新的 JS 语法
  16. ecmaVersion: 2020,
  17. sourceType: 'module'
  18. },
  19. rules: {
  20. // 自定义规则
  21. 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  22. 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  23. // Vue 相关规则
  24. 'vue/multi-word-component-names': 'off', // 允许单单词组件名(如 Home.vue),方便仿制
  25. 'vue/no-unused-components': 'warn',
  26. // Prettier 冲突处理
  27. 'prettier/prettier': [
  28. 'error',
  29. {
  30. singleQuote: true, // 使用单引号
  31. semi: false, // 不使用分号(符合 B 站前端常见的现代风格)
  32. trailingComma: 'none', // 不使用尾随逗号
  33. printWidth: 100 // 每行最大字符数
  34. }
  35. ]
  36. }
  37. }