.eslintrc.cjs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. module.exports = {
  2. env: {
  3. browser: true,
  4. es2021: true,
  5. node: true
  6. },
  7. globals: {
  8. uni: 'readonly',
  9. getApp: 'readonly',
  10. wx: 'readonly',
  11. getCurrentPages: 'readonly',
  12. plus: 'readonly'
  13. },
  14. extends: [
  15. 'standard',
  16. './.eslintrc-auto-import.json',
  17. 'plugin:vue/vue3-recommended',
  18. 'plugin:vue-scoped-css/vue3-recommended'
  19. ],
  20. overrides: [
  21. ],
  22. parserOptions: {
  23. ecmaVersion: 'latest',
  24. sourceType: 'module'
  25. },
  26. plugins: [
  27. 'vue'
  28. ],
  29. rules: {
  30. // Possible Errors
  31. // 要求使用 let 或 const 而不是 var
  32. 'no-var': 'error',
  33. // 强制 "for" 循环中更新子句的计数器朝着正确的方向移动
  34. 'for-direction': 'error',
  35. // 强制 getter 函数中出现 return 语句
  36. 'getter-return': 'error',
  37. // 禁止在嵌套的块中出现变量声明或 function 声明
  38. 'no-inner-declarations': 'error',
  39. // 禁止由于 await 或 yield的使用而可能导致出现竞态条件的赋值
  40. 'require-atomic-updates': 'error',
  41. // console 警告
  42. // 'no-console': 'warn',
  43. 'no-restricted-syntax': [
  44. 'warn',
  45. {
  46. selector: "CallExpression[callee.object.name='console'][callee.property.name!=/^error$/]",
  47. message: '不允许使用 console.xxx,但可以使用 console.error'
  48. }
  49. ],
  50. // 禁止出现未使用过的变量
  51. 'no-unused-vars': [
  52. 'warn',
  53. {
  54. args: 'all',
  55. caughtErrors: 'none',
  56. ignoreRestSiblings: true,
  57. vars: 'all'
  58. }
  59. ],
  60. // 关闭名称校验
  61. 'vue/multi-word-component-names': 'off',
  62. // 非生产环境启用 debugger
  63. 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  64. // Best Practices
  65. eqeqeq: 'off',
  66. // Stylistic Issues
  67. // 强制可嵌套的块的最大深度
  68. 'max-depth': ['error', 5],
  69. // 强制函数最大代码行数
  70. 'max-lines-per-function': [
  71. 'error',
  72. {
  73. max: 150,
  74. skipBlankLines: true
  75. }
  76. ],
  77. // 强制回调函数最大嵌套深度
  78. 'max-nested-callbacks': ['error', { max: 10 }],
  79. // 强制函数定义中最多允许的参数数量
  80. 'max-params': ['error', { max: 5 }],
  81. // 强制每一行中所允许的最大语句数量
  82. 'max-statements-per-line': ['error', { max: 1 }],
  83. // 三目运算符换行
  84. 'multiline-ternary': ['error', 'never'],
  85. // 传值给组件时的使用 kebab-case
  86. 'vue/v-on-event-hyphenation': ['warn', 'always', {
  87. autofix: true,
  88. ignore: []
  89. }]
  90. }
  91. }