.eslintrc.cjs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. module.exports = {
  2. "root":true,
  3. "env": {
  4. "browser": true,
  5. "es2021": true
  6. },
  7. "extends": [
  8. "eslint:recommended",
  9. "plugin:vue/vue3-essential",
  10. "plugin:@typescript-eslint/recommended"
  11. ],
  12. "overrides": [
  13. ],
  14. "parser": "vue-eslint-parser",
  15. "parserOptions": {
  16. "ecmaVersion": "latest",
  17. "parser":"@typescript-eslint/parser",
  18. "sourceType": "module"
  19. },
  20. "ignorePatterns":[".eslintrc.cjs"],
  21. "plugins": [
  22. "vue",
  23. "@typescript-eslint"
  24. ],
  25. "rules": {
  26. "for-direction": "error", // for 循环迭代条件是否正确
  27. "vue/component-name-in-template-casing": ["error", "kebab-case", {
  28. "registeredComponentsOnly": false,
  29. "ignores": []
  30. }],
  31. "vue/no-use-v-if-with-v-for": ["error", {
  32. "allowUsingIterationVar": false
  33. }],
  34. "vue/require-v-for-key": "error",
  35. "vue/prop-name-casing": ["error", "camelCase"],
  36. // getter 函数中出现 return 语句
  37. "getter-return": "error",
  38. // getter 函数中出现 return 语句
  39. "no-async-promise-executor": "error",
  40. // getter 函数中出现 return 语句
  41. "no-compare-neg-zero": "error",
  42. "vue/max-attributes-per-line": [2, {
  43. singleline: 10,
  44. multiline: {
  45. max: 1
  46. }
  47. }],
  48. "vue/v-bind-style": ["error", "shorthand"],
  49. "vue/v-on-style": ["error", "shorthand"],
  50. "vue/no-v-model-argument": "off",
  51. "vue/no-multiple-template-root": "off",
  52. "vue/singleline-html-element-content-newline": "off",
  53. "vue/multiline-html-element-content-newline": "off",
  54. "vue/component-definition-name-casing": ["error", "PascalCase"],
  55. "vue/no-v-html": "off",
  56. // 强制 getter 和 setter 在对象中成对出现
  57. "accessor-pairs": 2,
  58. // 强制箭头函数的箭头前后使用一致的空格
  59. "arrow-spacing": [2, {
  60. before: true,
  61. after: true
  62. }],
  63. // 禁止或强制在代码块中开括号前和闭括号后有空格
  64. "block-spacing": [2, "always"],
  65. // 强制在代码块中使用一致的大括号风格
  66. "brace-style": [2, "1tbs", {
  67. allowSingleLine: true
  68. }],
  69. // 强制使用骆驼拼写法命名约定
  70. camelcase: [0, {
  71. properties: "always"
  72. }],
  73. // 要求或禁止末尾逗号
  74. "comma-dangle": [2, "never"],
  75. // 强制在逗号前后使用一致的空格
  76. "comma-spacing": [2, {
  77. before: false,
  78. after: true
  79. }],
  80. // 强制使用一致的逗号风格
  81. "comma-style": [2, "last"],
  82. // 要求在构造函数中有 super() 的调用
  83. "constructor-super": 2,
  84. // 强制所有控制语句使用一致的括号风格
  85. curly: [2, "multi-line"],
  86. "dot-location": [2, "property"], // 强制在点号之前和之后一致的换行
  87. "eol-last": 2, // 要求或禁止文件末尾存在空行
  88. eqeqeq: ["error", "always", { null: "ignore" }], // 要求使用 === 和 !==
  89. "generator-star-spacing": [2, {
  90. before: true,
  91. after: true
  92. }], // 强制 generator 函数中 * 号周围使用一致的空格
  93. "handle-callback-err": [2, "^(err|error)$"], // 要求回调函数中有容错处理
  94. indent: [2, 2, {
  95. SwitchCase: 1
  96. }], // 强制使用一致的缩进
  97. "jsx-quotes": [2, "prefer-single"], // 强制在 JSX 属性中一致地使用双引号或单引号
  98. "key-spacing": [2, {
  99. beforeColon: false,
  100. afterColon: true
  101. }], // 强制在对象字面量的属性中键和值之间使用一致的间距
  102. "keyword-spacing": [2, {
  103. before: true,
  104. after: true
  105. }], // 强制在关键字前后使用一致的空格
  106. "new-cap": [2, {
  107. newIsCap: true,
  108. capIsNew: false
  109. }], // 要求构造函数首字母大写
  110. "new-parens": 2, // 强制或禁止调用无参构造函数时有圆括号
  111. "no-array-constructor": 2, // 禁用 Array 构造函数
  112. "no-caller": 2, // 禁用 arguments.caller 或 arguments.callee
  113. "no-console": "off",
  114. "no-class-assign": 2, // 禁止修改类声明的变量
  115. "no-cond-assign": 2, // 禁止条件表达式中出现赋值操作符
  116. "no-const-assign": 2,
  117. "no-control-regex": 0, // 禁止在正则表达式中使用控制字符
  118. "no-delete-var": 2, // 禁止删除变量
  119. "no-dupe-args": 2, // 禁止 function 定义中出现重名参数
  120. "no-dupe-class-members": 2, // 禁止类成员中出现重复的名称
  121. "no-dupe-keys": 2, // 禁止对象字面量中出现重复的 key
  122. "no-duplicate-case": 2, // 禁止出现重复的 case 标签
  123. "no-empty-character-class": 2, // 禁止在正则表达式中使用空字符集
  124. "no-empty-pattern": 2, // 禁止使用空解构模式
  125. "no-eval": 2, // 禁用 eval()
  126. "no-ex-assign": 2, // 禁止对 catch 子句的参数重新赋值
  127. "no-extend-native": 2, // 禁止扩展原生类型
  128. "no-extra-bind": 2, // 禁止不必要的 .bind() 调用
  129. "no-extra-boolean-cast": 2, // 禁止不必要的布尔转换
  130. "no-extra-parens": [2, "functions"], // 禁止不必要的括号
  131. "no-fallthrough": 2, // 禁止 case 语句落空
  132. "no-floating-decimal": 2, // 禁止数字字面量中使用前导和末尾小数点
  133. "no-func-assign": 2, // 禁止对 function 声明重新赋值
  134. "no-implied-eval": 2, // 禁止使用类似 eval() 的方法
  135. "no-inner-declarations": [2, "functions"],
  136. "no-invalid-regexp": 2, // 禁止在嵌套的块中出现变量声明或 function 声明
  137. "no-irregular-whitespace": 2, // 禁止不规则的空白
  138. "no-iterator": 2, // 禁用 __iterator__ 属性
  139. "no-label-var": 2, // 不允许标签与变量同名
  140. "no-labels": [2, {
  141. allowLoop: false,
  142. allowSwitch: false
  143. }], // 禁用标签语句
  144. "no-lone-blocks": 2, // 禁用不必要的嵌套块
  145. "no-mixed-spaces-and-tabs": 2, // 禁止空格和 tab 的混合缩进
  146. "no-multi-spaces": 2, // 禁止使用多个空格
  147. "no-multi-str": 2, // 禁止使用多行字符串
  148. "no-multiple-empty-lines": [2, {
  149. max: 1
  150. }], // 禁止出现多行空行
  151. "no-global-assign": 2, // no-global-assign
  152. "no-unsafe-negation": 2, // 禁止对关系运算符的左操作数使用否定操作符
  153. "no-new-object": 2, // 禁用 Object 的构造函数
  154. "no-new-require": 2, // 禁止调用 require 时使用 new 操作符
  155. "no-new-symbol": 2, // 禁止 Symbolnew 操作符和 new 一起使用
  156. "no-new-wrappers": 2, // 禁止对 String,Number 和 Boolean 使用 new 操作符
  157. "no-obj-calls": 2, // 禁止把全局对象作为函数调用
  158. "no-octal": 2, // 禁用八进制字面量
  159. "no-octal-escape": 2, // 禁止在字符串中使用八进制转义序列
  160. "no-path-concat": 2, // 禁止对 __dirname 和 __filename 进行字符串连接
  161. "no-proto": 2, // 禁用 __proto__ 属性
  162. "no-redeclare": 2, // 禁止多次声明同一变量
  163. "no-regex-spaces": 2, // 禁止正则表达式字面量中出现多个空格
  164. "no-return-assign": [2, "except-parens"], // 禁止在 return 语句中使用赋值语句
  165. "no-self-assign": 2, // 禁止自我赋值
  166. "no-self-compare": 2, // 禁止自身比较
  167. "no-sequences": 2, // 禁用逗号操作符
  168. "no-shadow-restricted-names": 2, // 禁止将标识符定义为受限的名字
  169. "func-call-spacing": 2, // 要求或禁止在函数名和开括号之间有空格。
  170. "no-sparse-arrays": 2, // 禁用稀疏数组
  171. "no-this-before-super": 2, // 禁止在构造函数中,在调用 super() 之前使用 this 或 super
  172. "no-throw-literal": 2, // 禁止抛出异常字面量
  173. "no-trailing-spaces": 2, // 禁用行尾空格
  174. "no-undef": 2, // 禁用未声明的变量,除非它们在 /*global */ 注释中被提到
  175. "no-undef-init": 2, // 禁止将变量初始化为 undefined
  176. "no-unexpected-multiline": 2, // 禁止出现令人困惑的多行表达式
  177. "no-unmodified-loop-condition": 2, // 禁用一成不变的循环条件
  178. "no-unneeded-ternary": [2, {
  179. defaultAssignment: false
  180. }], // 禁止可以在有更简单的可替代的表达式时使用三元操作符
  181. "no-unreachable": 2, // 禁止在 return、throw、continue 和 break 语句之后出现不可达代码
  182. "no-unsafe-finally": 2, // 禁止在 finally 语句块中出现控制流语句
  183. "no-unused-vars": [2, {
  184. vars: "all",
  185. args: "none"
  186. }], // 禁止出现未使用过的变量
  187. "no-useless-call": 2, // 禁止不必要的 .call() 和 .apply()
  188. "no-useless-computed-key": 2, // 禁止在对象中使用不必要的计算属性
  189. "no-useless-constructor": 2, // 禁用不必要的构造函数
  190. "no-useless-escape": 0, // 禁用不必要的转义字符
  191. "no-whitespace-before-property": 2, // 禁止属性前有空白
  192. "no-with": 2, // 禁用 with 语句
  193. "one-var": [2, {
  194. initialized: "never"
  195. }], // 强制函数中的变量要么一起声明要么分开声明
  196. "operator-linebreak": [2, "after", {
  197. overrides: {
  198. "?": "before",
  199. ":": "before"
  200. }
  201. }], // 强制操作符使用一致的换行符
  202. "padded-blocks": [2, "never"], // 要求或禁止块内填充
  203. quotes: [2, "single", {
  204. avoidEscape: true,
  205. allowTemplateLiterals: true
  206. }], // 强制使用一致的反勾号、双引号或单引号
  207. semi: [2, "never"],
  208. "semi-spacing": [2, {
  209. before: false,
  210. after: true
  211. }], // 强制分号之前和之后使用一致的空格
  212. "space-before-blocks": [2, "always"],
  213. "space-before-function-paren": [2, "never"],
  214. "space-in-parens": [2, "never"],
  215. "space-infix-ops": 2,
  216. "space-unary-ops": [2, {
  217. words: true,
  218. nonwords: false
  219. }], // 强制在一元操作符前后使用一致的空格
  220. "spaced-comment": [2, "always", {
  221. markers: ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","]
  222. }], // 强制在注释中 // 或 /* 使用一致的空格
  223. "template-curly-spacing": [2, "never"], // 要求或禁止模板字符串中的嵌入表达式周围空格的使用
  224. "use-isnan": 2, // 要求使用 isNaN() 检查 NaN
  225. "valid-typeof": 2,
  226. "wrap-iife": [2, "any"],
  227. "yield-star-spacing": [2, "both"],
  228. yoda: [2, "never"], // 要求或禁止 “Yoda” 条件
  229. "prefer-const": [
  230. "error",
  231. {
  232. destructuring: "all",
  233. ignoreReadBeforeAssign: false
  234. }
  235. ], // 要求使用 const 声明那些声明后不再被修改的变量
  236. "no-debugger": process.env.NODE_ENV === "production" ? 2 : 0,
  237. "object-curly-spacing": [2, "always", {
  238. objectsInObjects: false
  239. }], // 强制在大括号中使用一致的空格
  240. "array-bracket-spacing": [2, "never"],
  241. "default-case": "off", // 要求 switch 语句中有 default 分支
  242. "no-plusplus": "off", // 禁用一元操作符 ++ 和 --
  243. "guard-for-in": "off",
  244. "max-len": "off", // 强制一行的最大长度
  245. "no-param-reassign": "off", // 禁止对 function 的参数进行重新赋值
  246. "import/no-unresolved": "off", // 确保导入指向一个可以解析的文件/模块
  247. "import/extensions": "off", // 确保在导入路径中统一使用文件扩展名
  248. "no-bitwise": "off", // 禁用按位运算符
  249. "@typescript-eslint/no-explicit-any": "off",
  250. "consistent-return": "off",
  251. "array-callback-return": "off",
  252. "import/no-extraneous-dependencies": "off",
  253. "no-restricted-syntax": "off",
  254. radix: "off", // 强制在 parseInt() 使用基数参数
  255. "linebreak-style": ["error", "unix"], // 强制使用一致的换行风格
  256. "import/prefer-default-export": "off", // 如果模块只输入一个名字,则倾向于默认输出
  257. "prefer-destructuring": "off", // 优先使用数组和对象解构
  258. "import/no-cycle": "off", // 禁止一个模块导入一个有依赖路径的模块回到自己身上
  259. "arrow-parens": "off", // 要求箭头函数的参数使用圆括号
  260. "no-continue": "off", // 禁用 continue 语句
  261. "no-prototype-builtins": "off", // 禁止直接调用 Object.prototypes 的内置属性
  262. "import/named": "off", // 确保命名导入与远程文件中的命名导出相对应
  263. "object-curly-newline": "off", // 强制大括号内换行符的一致性
  264. "func-names": "off", // 要求或禁止使用命名的 function 表达式
  265. "no-unused-expressions": "off", // 禁止出现未使用过的表达式
  266. "no-underscore-dangle": "off", // 禁止标识符中有悬空下划线
  267. "no-nested-ternary": "off", // 禁用嵌套的三元表达式
  268. "no-await-in-loop": "off", // 禁止在循环中出现 await
  269. "@typescript-eslint/no-empty-function": "off", // 不允许空函数
  270. "vue/html-indent": ["error", 2], // 在<template>中强制一致缩进
  271. "vue/multi-word-component-names": "off", // 组件命名必须为多词
  272. "vue/html-self-closing": ["error", {
  273. "html": {
  274. "void": "always",
  275. "normal": "always",
  276. "component": "always"
  277. },
  278. "svg": "always",
  279. "math": "always"
  280. }]
  281. }
  282. }