.eslintrc.cjs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // 禁止出现未使用过的变量
  44. 'no-unused-vars': [
  45. 'warn',
  46. {
  47. args: 'all',
  48. caughtErrors: 'none',
  49. ignoreRestSiblings: true,
  50. vars: 'all',
  51. // 符合规则的参数名将会忽略
  52. argsIgnorePattern: '^[rule, value, data, i, to, from]'
  53. }
  54. ],
  55. // 关闭名称校验
  56. 'vue/multi-word-component-names': 'off',
  57. // 非生产环境启用 debugger
  58. 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  59. // Best Practices
  60. eqeqeq: 'off',
  61. // Stylistic Issues
  62. // 强制可嵌套的块的最大深度
  63. 'max-depth': ['error', 5],
  64. // 强制函数最大代码行数
  65. 'max-lines-per-function': [
  66. 'error',
  67. {
  68. max: 150,
  69. skipBlankLines: true
  70. }
  71. ],
  72. // 强制回调函数最大嵌套深度
  73. 'max-nested-callbacks': ['error', { max: 10 }],
  74. // 强制函数定义中最多允许的参数数量
  75. 'max-params': ['error', { max: 5 }],
  76. // 强制每一行中所允许的最大语句数量
  77. 'max-statements-per-line': ['error', { max: 1 }],
  78. // 三目运算符换行
  79. 'multiline-ternary': ['error', 'never'],
  80. // 传值给组件时的使用 kebab-case
  81. 'vue/v-on-event-hyphenation': ['warn', 'always', {
  82. autofix: true,
  83. ignore: []
  84. }]
  85. }
  86. }