.eslintrc.cjs 6.5 KB

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