eslint.config.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. import eslintPluginBetterTailwindcss from "eslint-plugin-better-tailwindcss";
  9. export default defineConfig([
  10. globalIgnores([
  11. "**/.*",
  12. "dist/*",
  13. "*.d.ts",
  14. "public/*",
  15. "src/assets/**",
  16. "src/**/iconfont/**"
  17. ]),
  18. {
  19. ...js.configs.recommended,
  20. languageOptions: {
  21. globals: {
  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. "no-restricted-syntax": "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. {
  173. files: ["**/*.vue", "**/*.tsx"],
  174. plugins: {
  175. "better-tailwindcss": eslintPluginBetterTailwindcss
  176. },
  177. rules: {
  178. "better-tailwindcss/enforce-consistent-variable-syntax": "warn",
  179. "better-tailwindcss/enforce-canonical-classes": "warn"
  180. },
  181. settings: {
  182. "better-tailwindcss": {
  183. entryPoint: "src/style/tailwind.css",
  184. rootFontSize: 16
  185. }
  186. }
  187. }
  188. ]);