eslint.config.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.configs.recommended.map(config => ({
  75. ...config,
  76. files: ["**/*.?([cm])ts", "**/*.?([cm])tsx"]
  77. })),
  78. {
  79. files: ["**/*.?([cm])ts", "**/*.?([cm])tsx"],
  80. rules: {
  81. "@typescript-eslint/no-redeclare": "error",
  82. "@typescript-eslint/ban-ts-comment": "off",
  83. "@typescript-eslint/no-explicit-any": "off",
  84. "@typescript-eslint/prefer-as-const": "warn",
  85. "@typescript-eslint/no-empty-function": "off",
  86. "@typescript-eslint/no-non-null-assertion": "off",
  87. "@typescript-eslint/no-unused-expressions": "off",
  88. "@typescript-eslint/no-unsafe-function-type": "off",
  89. "@typescript-eslint/no-import-type-side-effects": "error",
  90. "@typescript-eslint/explicit-module-boundary-types": "off",
  91. "@typescript-eslint/consistent-type-imports": [
  92. "error",
  93. { disallowTypeAnnotations: false, fixStyle: "inline-type-imports" }
  94. ],
  95. "@typescript-eslint/prefer-literal-enum-member": [
  96. "error",
  97. { allowBitwiseExpressions: true }
  98. ],
  99. "@typescript-eslint/no-unused-vars": [
  100. "error",
  101. {
  102. argsIgnorePattern: "^_",
  103. varsIgnorePattern: "^_"
  104. }
  105. ]
  106. }
  107. },
  108. {
  109. files: ["**/*.d.ts"],
  110. rules: {
  111. "eslint-comments/no-unlimited-disable": "off",
  112. "import/no-duplicates": "off",
  113. "no-restricted-syntax": "off",
  114. "unused-imports/no-unused-vars": "off"
  115. }
  116. },
  117. {
  118. files: ["**/*.?([cm])js"],
  119. rules: {
  120. "@typescript-eslint/no-require-imports": "off"
  121. }
  122. },
  123. {
  124. files: ["**/*.vue"],
  125. languageOptions: {
  126. globals: {
  127. $: "readonly",
  128. $$: "readonly",
  129. $computed: "readonly",
  130. $customRef: "readonly",
  131. $ref: "readonly",
  132. $shallowRef: "readonly",
  133. $toRef: "readonly"
  134. },
  135. parser: parserVue,
  136. parserOptions: {
  137. ecmaFeatures: {
  138. jsx: true
  139. },
  140. extraFileExtensions: [".vue"],
  141. parser: tseslint.parser,
  142. sourceType: "module"
  143. }
  144. },
  145. plugins: {
  146. "@typescript-eslint": tseslint.plugin,
  147. vue: pluginVue
  148. },
  149. processor: pluginVue.processors[".vue"],
  150. rules: {
  151. ...pluginVue.configs.base.rules,
  152. ...pluginVue.configs.essential.rules,
  153. ...pluginVue.configs.recommended.rules,
  154. "no-undef": "off",
  155. "no-unused-vars": "off",
  156. "vue/no-v-html": "off",
  157. "vue/require-default-prop": "off",
  158. "vue/require-explicit-emits": "off",
  159. "vue/multi-word-component-names": "off",
  160. "vue/no-setup-props-reactivity-loss": "off",
  161. "vue/html-self-closing": [
  162. "error",
  163. {
  164. html: {
  165. void: "always",
  166. normal: "always",
  167. component: "always"
  168. },
  169. svg: "always",
  170. math: "always"
  171. }
  172. ]
  173. }
  174. }
  175. ]);