eslint.config.js 4.9 KB

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