eslint.config.js 4.6 KB

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