eslint.config.mjs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * Copyright (c) 2013-Now https://jeesite.com All rights reserved.
  3. * No deletion without permission, or be held responsible to law.
  4. * @author ThinkGem
  5. */
  6. import globals from 'globals';
  7. import vuePlugin from 'eslint-plugin-vue';
  8. import tsPlugin from '@typescript-eslint/eslint-plugin';
  9. import prettierPlugin from 'eslint-plugin-prettier';
  10. import tsParser from '@typescript-eslint/parser';
  11. import vueParser from 'vue-eslint-parser';
  12. import babelParser from '@babel/eslint-parser';
  13. export default [
  14. // 基础忽略配置
  15. {
  16. ignores: [
  17. '**/node_modules/',
  18. '**/dist/',
  19. '**/public/',
  20. '**/build/',
  21. '**/.git/',
  22. '**/.vscode/',
  23. '**/.idea/',
  24. '**/.husky/',
  25. '**/.local/',
  26. '**/.turbo/',
  27. '**/Dockerfile',
  28. '**/*.sh',
  29. '**/*.md',
  30. '**/*.woff',
  31. '**/*.ttf',
  32. '**/*.d.ts',
  33. '**/__snapshots__/',
  34. ],
  35. },
  36. // 公共基础配置
  37. {
  38. languageOptions: {
  39. ecmaVersion: 'latest',
  40. sourceType: 'module',
  41. globals: {
  42. ...globals.browser,
  43. ...globals.node,
  44. defineOptions: 'readonly',
  45. },
  46. parserOptions: {
  47. requireConfigFile: false,
  48. },
  49. },
  50. rules: {
  51. // 通用规则
  52. 'no-case-declarations': 'off',
  53. 'no-extra-boolean-cast': 'off',
  54. 'no-undef': 'off',
  55. 'space-before-function-paren': 'off',
  56. },
  57. },
  58. // Vue 文件配置
  59. {
  60. files: ['**/*.vue'],
  61. plugins: {
  62. vue: vuePlugin,
  63. },
  64. languageOptions: {
  65. parser: vueParser,
  66. parserOptions: {
  67. parser: {
  68. ts: tsParser,
  69. tsx: tsParser,
  70. js: babelParser,
  71. '<template>': 'espree',
  72. },
  73. ecmaFeatures: {
  74. jsx: true,
  75. },
  76. },
  77. },
  78. rules: {
  79. // ...vuePlugin.configs['vue3-recommended'].rules,
  80. // 'vue/script-setup-uses-vars': 'error',
  81. 'vue/no-reserved-component-names': 'off',
  82. 'vue/custom-event-name-casing': 'off',
  83. 'vue/attributes-order': 'off',
  84. 'vue/one-component-per-file': 'off',
  85. 'vue/html-closing-bracket-newline': 'off',
  86. 'vue/max-attributes-per-line': 'off',
  87. 'vue/multiline-html-element-content-newline': 'off',
  88. 'vue/singleline-html-element-content-newline': 'off',
  89. 'vue/attribute-hyphenation': 'off',
  90. 'vue/require-default-prop': 'off',
  91. 'vue/require-explicit-emits': 'off',
  92. 'vue/html-self-closing': [
  93. 'error',
  94. {
  95. html: {
  96. void: 'always',
  97. normal: 'never',
  98. component: 'always',
  99. },
  100. svg: 'always',
  101. math: 'always',
  102. },
  103. ],
  104. 'vue/multi-word-component-names': 'off',
  105. 'vue/no-v-html': 'off',
  106. },
  107. },
  108. // TypeScript 配置
  109. {
  110. files: ['**/*.ts', '**/*.tsx'],
  111. plugins: {
  112. '@typescript-eslint': tsPlugin,
  113. },
  114. languageOptions: {
  115. parser: tsParser,
  116. parserOptions: {
  117. // project: './tsconfig.json',
  118. // jsxPragma: 'React',
  119. ecmaFeatures: {
  120. jsx: true, // 启用 JSX 支持
  121. },
  122. },
  123. },
  124. rules: {
  125. ...tsPlugin.configs.recommended.rules,
  126. '@typescript-eslint/ban-ts-comment': 'off',
  127. '@typescript-eslint/ban-types': 'off',
  128. '@typescript-eslint/explicit-module-boundary-types': 'off',
  129. '@typescript-eslint/no-empty-function': 'off',
  130. '@typescript-eslint/no-explicit-any': 'off',
  131. '@typescript-eslint/no-non-null-assertion': 'off',
  132. '@typescript-eslint/no-unused-expressions': 'off',
  133. '@typescript-eslint/no-unused-vars': 'off',
  134. '@typescript-eslint/no-use-before-define': 'off',
  135. '@typescript-eslint/no-var-requires': 'off',
  136. '@typescript-eslint/no-unsafe-function-type': 'off',
  137. },
  138. },
  139. // JavaScript 配置
  140. {
  141. files: ['**/*.js'],
  142. languageOptions: {
  143. parser: babelParser,
  144. parserOptions: {
  145. requireConfigFile: false,
  146. babelOptions: {
  147. presets: ['@babel/preset-env'],
  148. plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]],
  149. },
  150. },
  151. },
  152. },
  153. // Prettier 集成配置
  154. {
  155. plugins: {
  156. prettier: prettierPlugin,
  157. },
  158. rules: {
  159. 'prettier/prettier': [
  160. 'error',
  161. {
  162. printWidth: 120,
  163. semi: true,
  164. singleQuote: true,
  165. trailingComma: 'all',
  166. },
  167. ],
  168. 'property-sort-order': 'off',
  169. },
  170. },
  171. ];