.eslintrc.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. module.exports = {
  2. root: true,
  3. env: {
  4. browser: true,
  5. es2021: true,
  6. node: true
  7. },
  8. extends: [
  9. 'eslint:recommended',
  10. 'plugin:vue/vue3-recommended',
  11. 'plugin:prettier/recommended'
  12. ],
  13. parserOptions: {
  14. ecmaVersion: 2021,
  15. sourceType: 'module',
  16. ecmaFeatures: {
  17. jsx: true
  18. }
  19. },
  20. plugins: ['vue', 'prettier'],
  21. rules: {
  22. // Vue规则
  23. 'vue/multi-word-component-names': 'off',
  24. 'vue/no-v-html': 'off',
  25. 'vue/require-default-prop': 'off',
  26. 'vue/require-explicit-emits': 'off',
  27. 'vue/no-setup-props-destructure': 'off',
  28. // 基础规则
  29. 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  30. 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  31. 'no-unused-vars': ['error', {
  32. argsIgnorePattern: '^_',
  33. varsIgnorePattern: '^_'
  34. }],
  35. 'no-empty': ['error', { allowEmptyCatch: true }],
  36. // 代码风格
  37. 'indent': ['error', 2, { SwitchCase: 1 }],
  38. 'quotes': ['error', 'single', { avoidEscape: true }],
  39. 'semi': ['error', 'always'],
  40. 'comma-dangle': ['error', 'only-multiline'],
  41. 'object-curly-spacing': ['error', 'always'],
  42. 'array-bracket-spacing': ['error', 'never'],
  43. 'arrow-parens': ['error', 'always'],
  44. 'arrow-spacing': ['error', { before: true, after: true }],
  45. 'space-before-blocks': ['error', 'always'],
  46. 'keyword-spacing': ['error', { before: true, after: true }],
  47. // Prettier集成
  48. 'prettier/prettier': ['error', {
  49. singleQuote: true,
  50. semi: true,
  51. useTabs: false,
  52. tabWidth: 2,
  53. trailingComma: 'only-multiline',
  54. printWidth: 100,
  55. bracketSpacing: true,
  56. arrowParens: 'always',
  57. endOfLine: 'auto'
  58. }]
  59. },
  60. globals: {
  61. defineProps: 'readonly',
  62. defineEmits: 'readonly',
  63. defineExpose: 'readonly',
  64. withDefaults: 'readonly'
  65. },
  66. // 忽略的文件和目录(从 .eslintignore 合并而来)
  67. ignorePatterns: [
  68. // 依赖和构建输出
  69. 'node_modules/',
  70. 'dist/',
  71. 'dist-*',
  72. 'build/',
  73. 'coverage/',
  74. // 编辑器相关
  75. '.idea/',
  76. '.vscode/',
  77. '*.suo',
  78. '*.ntvs*',
  79. '*.njsproj',
  80. '*.sln',
  81. '*.sw?',
  82. // 日志文件
  83. '*-debug.log*',
  84. '*-error.log*',
  85. // 环境配置
  86. '.env.local',
  87. '.env.*.local',
  88. // 编译输出
  89. '*.min.js',
  90. '*.min.css',
  91. // 其他
  92. '.DS_Store',
  93. 'public/',
  94. '*.md',
  95. '*.json',
  96. '*.yaml',
  97. '*.yml',
  98. '*.lock',
  99. // 静态资源
  100. 'src/assets/',
  101. '*.svg',
  102. '*.png',
  103. '*.jpg',
  104. '*.jpeg',
  105. '*.gif',
  106. '*.ico',
  107. // 打包文件
  108. '*.zip',
  109. '*.tar.gz'
  110. ]
  111. };