You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

.eslintrc.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. module.exports = {
  2. root: true,
  3. env: {
  4. browser: true,
  5. node: true,
  6. es2021: true,
  7. },
  8. parser: 'vue-eslint-parser',
  9. extends: [
  10. 'eslint:recommended',
  11. 'plugin:vue/vue3-recommended',
  12. 'plugin:@typescript-eslint/recommended',
  13. 'plugin:prettier/recommended',
  14. // eslint-config-prettier 的缩写
  15. 'prettier',
  16. ],
  17. parserOptions: {
  18. ecmaVersion: 12,
  19. parser: '@typescript-eslint/parser',
  20. sourceType: 'module',
  21. ecmaFeatures: {
  22. jsx: true,
  23. },
  24. },
  25. // eslint-plugin-vue @typescript-eslint/eslint-plugin eslint-plugin-prettier的缩写
  26. plugins: ['vue', '@typescript-eslint', 'prettier'],
  27. rules: {
  28. '@typescript-eslint/ban-ts-ignore': 'off',
  29. '@typescript-eslint/no-unused-vars': 'off',
  30. '@typescript-eslint/explicit-function-return-type': 'off',
  31. '@typescript-eslint/no-explicit-any': 'off',
  32. '@typescript-eslint/no-var-requires': 'off',
  33. '@typescript-eslint/no-empty-function': 'off',
  34. '@typescript-eslint/no-use-before-define': 'off',
  35. '@typescript-eslint/ban-ts-comment': 'off',
  36. '@typescript-eslint/ban-types': 'off',
  37. '@typescript-eslint/no-non-null-assertion': 'off',
  38. '@typescript-eslint/explicit-module-boundary-types': 'off',
  39. 'no-var': 'error',
  40. 'vue/no-use-v-if-with-v-for': 'off',
  41. 'prettier/prettier': 'error',
  42. // 禁止出现console
  43. // 'no-console': 'warn',
  44. // 禁用debugger
  45. 'no-debugger': 'warn',
  46. // 禁止出现重复的 case 标签
  47. 'no-duplicate-case': 'warn',
  48. // 禁止出现空语句块
  49. // 'no-empty': 'warn',
  50. // 禁止不必要的括号
  51. 'no-extra-parens': 'off',
  52. // 禁止对 function 声明重新赋值
  53. 'no-func-assign': 'warn',
  54. // 禁止在 return、throw、continue 和 break 语句之后出现不可达代码
  55. 'no-unreachable': 'warn',
  56. // 强制所有控制语句使用一致的括号风格
  57. curly: 'warn',
  58. // 要求 switch 语句中有 default 分支
  59. 'default-case': 'warn',
  60. // 强制尽可能地使用点号
  61. // 'dot-notation': 'warn',
  62. // 要求使用 === 和 !==
  63. eqeqeq: 'warn',
  64. // 禁止 if 语句中 return 语句之后有 else 块
  65. 'no-else-return': 'warn',
  66. // 禁止出现空函数
  67. 'no-empty-function': 'warn',
  68. // 禁用不必要的嵌套块
  69. 'no-lone-blocks': 'warn',
  70. // 禁止使用多个空格
  71. 'no-multi-spaces': 'warn',
  72. // 禁止多次声明同一变量
  73. 'no-redeclare': 'warn',
  74. // 禁止在 return 语句中使用赋值语句
  75. 'no-return-assign': 'warn',
  76. // 禁用不必要的 return await
  77. 'no-return-await': 'warn',
  78. // 禁止自我赋值
  79. 'no-self-assign': 'warn',
  80. // 禁止自身比较
  81. 'no-self-compare': 'warn',
  82. // 禁止不必要的 catch 子句
  83. 'no-useless-catch': 'warn',
  84. // 禁止多余的 return 语句
  85. 'no-useless-return': 'warn',
  86. // 禁止变量声明与外层作用域的变量同名
  87. 'no-shadow': 'off',
  88. // 允许delete变量
  89. 'no-delete-var': 'off',
  90. // 强制数组方括号中使用一致的空格
  91. 'array-bracket-spacing': 'warn',
  92. // 强制在代码块中使用一致的大括号风格
  93. 'brace-style': 'warn',
  94. // 强制使用骆驼拼写法命名约定
  95. camelcase: 'warn',
  96. // 强制使用一致的缩进
  97. indent: 'off',
  98. // 强制在 JSX 属性中一致地使用双引号或单引号
  99. 'jsx-quotes': 'warn',
  100. // 强制可嵌套的块的最大深度4
  101. 'max-depth': 'warn',
  102. // 强制最大行数 300
  103. // "max-lines": ["warn", { "max": 1200 }],
  104. // 强制函数最大代码行数 50
  105. // 'max-lines-per-function': ['warn', { max: 70 }],
  106. // 强制函数块最多允许的的语句数量20
  107. 'max-statements': ['warn', 100],
  108. // 强制回调函数最大嵌套深度
  109. 'max-nested-callbacks': ['warn', 3],
  110. // 强制函数定义中最多允许的参数数量
  111. 'max-params': ['warn', 3],
  112. // 强制每一行中所允许的最大语句数量
  113. 'max-statements-per-line': ['warn', { max: 1 }],
  114. // 要求方法链中每个调用都有一个换行符
  115. 'newline-per-chained-call': ['warn', { ignoreChainWithDepth: 3 }],
  116. // 禁止 if 作为唯一的语句出现在 else 语句中
  117. 'no-lonely-if': 'warn',
  118. // 禁止空格和 tab 的混合缩进
  119. 'no-mixed-spaces-and-tabs': 'warn',
  120. // 禁止出现多行空行
  121. 'no-multiple-empty-lines': 'warn',
  122. // 禁止出现; //never 绝不
  123. // semi: ['warn', 'never'],
  124. // 强制在块之前使用一致的空格
  125. 'space-before-blocks': 'warn',
  126. // 强制在 function的左括号之前使用一致的空格
  127. // 'space-before-function-paren': ['warn', 'never'],
  128. // 强制在圆括号内使用一致的空格
  129. 'space-in-parens': 'warn',
  130. // 要求操作符周围有空格
  131. 'space-infix-ops': 'warn',
  132. // 强制在一元操作符前后使用一致的空格
  133. 'space-unary-ops': 'warn',
  134. // 强制在注释中 // 或 /* 使用一致的空格
  135. // "spaced-comment": "warn",
  136. // 强制在 switch 的冒号左右有空格
  137. 'switch-colon-spacing': 'warn',
  138. // 强制箭头函数的箭头前后使用一致的空格
  139. 'arrow-spacing': 'warn',
  140. 'prefer-const': 'warn', //指定常量
  141. // 必须使用 ...args 而不是 arguments
  142. // @off 没必要强制要求
  143. 'prefer-rest-params': 'warn',
  144. // 禁止出现没必要的转义
  145. // @off 转义可以使代码更易懂
  146. 'no-useless-escape': 'warn',
  147. // 禁止使用特殊空白符(比如全角空格),除非是出现在字符串、正则表达式或模版字符串中
  148. 'no-irregular-whitespace': 'warn',
  149. // 禁止使用 hasOwnProperty, isPrototypeOf 或 propertyIsEnumerable
  150. // @off hasOwnProperty 比较常用
  151. 'no-prototype-builtins': 'warn',
  152. // switch 的 case 内必须有 break, return 或 throw
  153. 'no-fallthrough': 'warn',
  154. // @fixable 禁止不必要的布尔类型转换,比如 !! 或 Boolean
  155. 'no-extra-boolean-cast': 'warn',
  156. // switch 的 case 内有变量定义的时候,必须使用大括号将 case 内变成一个代码块
  157. 'no-case-declarations': 'warn',
  158. 'no-async-promise-executor': 'warn',
  159. },
  160. globals: {
  161. defineProps: 'readonly',
  162. defineEmits: 'readonly',
  163. defineExpose: 'readonly',
  164. withDefaults: 'readonly',
  165. },
  166. }