.eslintrc.cjs 12 KB

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