.eslintrc.cjs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. module.exports = {
  2. env: {
  3. browser: true,
  4. es2021: true,
  5. node: true
  6. },
  7. extends: [
  8. "eslint:recommended",
  9. "standard-with-typescript",
  10. "plugin:vue/vue3-essential",
  11. "plugin:prettier/recommended",
  12. ],
  13. overrides: [
  14. {
  15. env: {
  16. node: true
  17. },
  18. files: [".eslintrc.{js,cjs}"],
  19. parserOptions: {
  20. sourceType: "script"
  21. }
  22. }
  23. ],
  24. parser: "vue-eslint-parser",
  25. parserOptions: {
  26. parser: "@typescript-eslint/parser",
  27. tsconfigRootDir: __dirname,
  28. project: ["tsconfig.json"],
  29. extraFileExtensions: [".vue"],
  30. ecmaVersion: "latest",
  31. sourceType: "module"
  32. },
  33. plugins: ["vue"],
  34. rules: {
  35. // eslint
  36. indent: [
  37. "error",
  38. "tab", // 缩进2个字符
  39. {
  40. ignoredNodes: ["ConditionalExpression"], // 忽略三元表达式
  41. SwitchCase: 1,
  42. VariableDeclarator: "first",
  43. outerIIFEBody: "off",
  44. MemberExpression: 1,
  45. FunctionDeclaration: { parameters: "first" },
  46. FunctionExpression: { parameters: "first" },
  47. CallExpression: { arguments: "first" },
  48. ArrayExpression: "first",
  49. ObjectExpression: "first",
  50. ImportDeclaration: "first",
  51. offsetTernaryExpressions: true
  52. }
  53. ],
  54. quotes: "off",
  55. eqeqeq: "off",
  56. "comma-dangle": "off",
  57. "no-tabs": ["off", { allowIndentationTabs: true }], // 允许tabs缩进
  58. "no-var": "error", // 要求使用 let 或 const 而不是 var
  59. "no-unused-vars": "off", // 禁止未使用过的变量
  60. "no-multiple-empty-lines": ["warn", { max: 1 }], // 不允许多个空行
  61. "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
  62. "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
  63. "no-unexpected-multiline": "error", // 禁止空余的多行
  64. "no-useless-escape": "off", // 禁止不必要的转义字符
  65. "spaced-comment": ["off", "always"],
  66. // typeScript (https://typescript-eslint.io/rules)
  67. "@typescript-eslint/quotes": ["off", "double"], // 使用双引号
  68. "@typescript-eslint/no-unused-vars": "error", // 禁止定义未使用的变量
  69. "@typescript-eslint/prefer-ts-expect-error": "error", // 禁止使用 @ts-ignore
  70. "@typescript-eslint/no-explicit-any": "off", // 禁止使用 any 类型
  71. "@typescript-eslint/no-non-null-assertion": "off",
  72. "@typescript-eslint/no-namespace": "off", // 禁止使用自定义 TypeScript 模块和命名空间。
  73. "@typescript-eslint/semi": "off",
  74. "@typescript-eslint/triple-slash-reference": "off",
  75. "@typescript-eslint/explicit-function-return-type": "off",
  76. "@typescript-eslint/strict-boolean-expressions": "off",
  77. "@typescript-eslint/no-dynamic-delete": "off",
  78. "@typescript-eslint/naming-convention": "off",
  79. "@typescript-eslint/consistent-type-assertions": "off",
  80. "@typescript-eslint/prefer-optional-chain": "off",
  81. "@typescript-eslint/restrict-plus-operands": "off",
  82. "@typescript-eslint/promise-function-async": "off",
  83. "@typescript-eslint/no-floating-promises": ["off", { ignoreVoid: true, ignoreIIFE: true }],
  84. "@typescript-eslint/no-this-alias": [
  85. "error",
  86. {
  87. allowDestructuring: false, // Disallow `const { props, state } = this`; true by default
  88. allowedNames: ["that"] // Allow `const self = this`; `[]` by default
  89. }
  90. ],
  91. // eslint-plugin-vue (https://eslint.vuejs.org/rules/)
  92. "vue/multi-word-component-names": "off", // 要求组件名称始终为 “-” 链接的单词
  93. "vue/script-setup-uses-vars": "error", // 防止<script setup>使用的变量<template>被标记为未使用
  94. "vue/no-mutating-props": "off", // 不允许组件 prop的改变
  95. "vue/attribute-hyphenation": "off", // 对模板中的自定义组件强制执行属性命名样式
  96. }
  97. }