eslint.config.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import js from "@eslint/js";
  2. import pluginVue from "eslint-plugin-vue";
  3. import * as parserVue from "vue-eslint-parser";
  4. import configPrettier from "eslint-config-prettier";
  5. import pluginPrettier from "eslint-plugin-prettier";
  6. import { defineFlatConfig } from "eslint-define-config";
  7. import * as parserTypeScript from "@typescript-eslint/parser";
  8. import pluginTypeScript from "@typescript-eslint/eslint-plugin";
  9. export default defineFlatConfig([
  10. {
  11. ...js.configs.recommended,
  12. ignores: ["src/assets/**", "src/**/iconfont/**"],
  13. languageOptions: {
  14. globals: {
  15. // index.d.ts
  16. RefType: "readonly",
  17. EmitType: "readonly",
  18. TargetContext: "readonly",
  19. ComponentRef: "readonly",
  20. ElRef: "readonly",
  21. ForDataType: "readonly",
  22. AnyFunction: "readonly",
  23. PropType: "readonly",
  24. Writable: "readonly",
  25. Nullable: "readonly",
  26. NonNullable: "readonly",
  27. Recordable: "readonly",
  28. ReadonlyRecordable: "readonly",
  29. Indexable: "readonly",
  30. DeepPartial: "readonly",
  31. Without: "readonly",
  32. Exclusive: "readonly",
  33. TimeoutHandle: "readonly",
  34. IntervalHandle: "readonly",
  35. Effect: "readonly",
  36. ChangeEvent: "readonly",
  37. WheelEvent: "readonly",
  38. ImportMetaEnv: "readonly",
  39. Fn: "readonly",
  40. PromiseFn: "readonly",
  41. ComponentElRef: "readonly",
  42. parseInt: "readonly",
  43. parseFloat: "readonly"
  44. }
  45. },
  46. plugins: {
  47. prettier: pluginPrettier
  48. },
  49. rules: {
  50. ...configPrettier.rules,
  51. ...pluginPrettier.configs.recommended.rules,
  52. "no-debugger": "off",
  53. "no-unused-vars": [
  54. "error",
  55. {
  56. argsIgnorePattern: "^_",
  57. varsIgnorePattern: "^_"
  58. }
  59. ],
  60. "prettier/prettier": [
  61. "error",
  62. {
  63. endOfLine: "auto"
  64. }
  65. ]
  66. }
  67. },
  68. {
  69. files: ["**/*.?([cm])ts", "**/*.?([cm])tsx"],
  70. languageOptions: {
  71. parser: parserTypeScript,
  72. parserOptions: {
  73. sourceType: "module"
  74. }
  75. },
  76. plugins: {
  77. "@typescript-eslint": pluginTypeScript
  78. },
  79. rules: {
  80. ...pluginTypeScript.configs.strict.rules,
  81. "@typescript-eslint/ban-types": "off",
  82. "@typescript-eslint/no-redeclare": "error",
  83. "@typescript-eslint/ban-ts-comment": "off",
  84. "@typescript-eslint/no-explicit-any": "off",
  85. "@typescript-eslint/prefer-as-const": "warn",
  86. "@typescript-eslint/no-empty-function": "off",
  87. "@typescript-eslint/no-non-null-assertion": "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. "unused-imports/no-unused-vars": "off"
  113. }
  114. },
  115. {
  116. files: ["**/*.?([cm])js"],
  117. rules: {
  118. "@typescript-eslint/no-require-imports": "off",
  119. "@typescript-eslint/no-var-requires": "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: "@typescript-eslint/parser",
  141. sourceType: "module"
  142. }
  143. },
  144. plugins: {
  145. vue: pluginVue
  146. },
  147. processor: pluginVue.processors[".vue"],
  148. rules: {
  149. ...pluginVue.configs.base.rules,
  150. ...pluginVue.configs["vue3-essential"].rules,
  151. ...pluginVue.configs["vue3-recommended"].rules,
  152. "no-undef": "off",
  153. "no-unused-vars": "off",
  154. "vue/no-v-html": "off",
  155. "vue/require-default-prop": "off",
  156. "vue/require-explicit-emits": "off",
  157. "vue/multi-word-component-names": "off",
  158. "vue/no-setup-props-reactivity-loss": "off",
  159. "vue/html-self-closing": [
  160. "error",
  161. {
  162. html: {
  163. void: "always",
  164. normal: "always",
  165. component: "always"
  166. },
  167. svg: "always",
  168. math: "always"
  169. }
  170. ]
  171. }
  172. }
  173. ]);