eslint.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import js from "@eslint/js";
  2. import tseslint from "typescript-eslint";
  3. import pluginVue from "eslint-plugin-vue";
  4. import * as parserVue from "vue-eslint-parser";
  5. import configPrettier from "eslint-config-prettier";
  6. import pluginPrettier from "eslint-plugin-prettier";
  7. import { defineConfig, globalIgnores } from "eslint/config";
  8. export default defineConfig([
  9. globalIgnores([
  10. "**/.*",
  11. "dist/*",
  12. "*.d.ts",
  13. "public/*",
  14. "src/assets/**",
  15. "src/**/iconfont/**"
  16. ]),
  17. {
  18. ...js.configs.recommended,
  19. languageOptions: {
  20. globals: {
  21. RefType: "readonly",
  22. EmitType: "readonly",
  23. TargetContext: "readonly",
  24. ComponentRef: "readonly",
  25. ElRef: "readonly",
  26. ForDataType: "readonly",
  27. AnyFunction: "readonly",
  28. PropType: "readonly",
  29. Writable: "readonly",
  30. Nullable: "readonly",
  31. NonNullable: "readonly",
  32. Recordable: "readonly",
  33. ReadonlyRecordable: "readonly",
  34. Indexable: "readonly",
  35. DeepPartial: "readonly",
  36. Without: "readonly",
  37. Exclusive: "readonly",
  38. TimeoutHandle: "readonly",
  39. IntervalHandle: "readonly",
  40. Effect: "readonly",
  41. ChangeEvent: "readonly",
  42. WheelEvent: "readonly",
  43. ImportMetaEnv: "readonly",
  44. Fn: "readonly",
  45. PromiseFn: "readonly",
  46. ComponentElRef: "readonly",
  47. parseInt: "readonly",
  48. parseFloat: "readonly"
  49. }
  50. },
  51. plugins: {
  52. prettier: pluginPrettier
  53. },
  54. rules: {
  55. ...configPrettier.rules,
  56. ...pluginPrettier.configs.recommended.rules,
  57. "no-debugger": "off",
  58. "no-unused-vars": [
  59. "error",
  60. {
  61. argsIgnorePattern: "^_",
  62. varsIgnorePattern: "^_"
  63. }
  64. ],
  65. "prettier/prettier": [
  66. "error",
  67. {
  68. endOfLine: "auto"
  69. }
  70. ]
  71. }
  72. },
  73. ...tseslint.configs.recommended.map(config => ({
  74. ...config,
  75. files: ["**/*.?([cm])ts", "**/*.?([cm])tsx"]
  76. })),
  77. {
  78. files: ["**/*.?([cm])ts", "**/*.?([cm])tsx"],
  79. rules: {
  80. "@typescript-eslint/no-redeclare": "error",
  81. "@typescript-eslint/ban-ts-comment": "off",
  82. "@typescript-eslint/no-explicit-any": "off",
  83. "@typescript-eslint/prefer-as-const": "warn",
  84. "@typescript-eslint/no-empty-function": "off",
  85. "@typescript-eslint/no-non-null-assertion": "off",
  86. "@typescript-eslint/no-unused-expressions": "off",
  87. "@typescript-eslint/no-unsafe-function-type": "off",
  88. "@typescript-eslint/no-import-type-side-effects": "error",
  89. "@typescript-eslint/explicit-module-boundary-types": "off",
  90. "@typescript-eslint/consistent-type-imports": [
  91. "error",
  92. { disallowTypeAnnotations: false, fixStyle: "inline-type-imports" }
  93. ],
  94. "@typescript-eslint/prefer-literal-enum-member": [
  95. "error",
  96. { allowBitwiseExpressions: true }
  97. ],
  98. "@typescript-eslint/no-unused-vars": [
  99. "error",
  100. {
  101. argsIgnorePattern: "^_",
  102. varsIgnorePattern: "^_"
  103. }
  104. ]
  105. }
  106. },
  107. {
  108. files: ["**/*.d.ts"],
  109. rules: {
  110. "eslint-comments/no-unlimited-disable": "off",
  111. "import/no-duplicates": "off",
  112. "no-restricted-syntax": "off",
  113. "unused-imports/no-unused-vars": "off"
  114. }
  115. },
  116. {
  117. files: ["**/*.?([cm])js"],
  118. rules: {
  119. "@typescript-eslint/no-require-imports": "off"
  120. }
  121. },
  122. {
  123. files: ["**/*.vue"],
  124. languageOptions: {
  125. globals: {
  126. $: "readonly",
  127. $$: "readonly",
  128. $computed: "readonly",
  129. $customRef: "readonly",
  130. $ref: "readonly",
  131. $shallowRef: "readonly",
  132. $toRef: "readonly"
  133. },
  134. parser: parserVue,
  135. parserOptions: {
  136. ecmaFeatures: {
  137. jsx: true
  138. },
  139. extraFileExtensions: [".vue"],
  140. parser: tseslint.parser,
  141. sourceType: "module"
  142. }
  143. },
  144. plugins: {
  145. "@typescript-eslint": tseslint.plugin,
  146. vue: pluginVue
  147. },
  148. processor: pluginVue.processors[".vue"],
  149. rules: {
  150. ...pluginVue.configs.base.rules,
  151. ...pluginVue.configs.essential.rules,
  152. ...pluginVue.configs.recommended.rules,
  153. "no-undef": "off",
  154. "no-unused-vars": "off",
  155. "vue/no-v-html": "off",
  156. "vue/require-default-prop": "off",
  157. "vue/require-explicit-emits": "off",
  158. "vue/multi-word-component-names": "off",
  159. "vue/no-setup-props-reactivity-loss": "off",
  160. "vue/html-self-closing": [
  161. "error",
  162. {
  163. html: {
  164. void: "always",
  165. normal: "always",
  166. component: "always"
  167. },
  168. svg: "always",
  169. math: "always"
  170. }
  171. ]
  172. }
  173. }
  174. ]);