eslint.config.mjs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 pluginImport from 'eslint-plugin-import';
  7. import { defineFlatConfig } from 'eslint-define-config';
  8. import * as parserTypeScript from '@typescript-eslint/parser';
  9. import pluginTypeScript from '@typescript-eslint/eslint-plugin';
  10. import unusedImports from 'eslint-plugin-unused-imports';
  11. export default defineFlatConfig([
  12. {
  13. ...js.configs.recommended,
  14. plugins: {
  15. prettier: pluginPrettier,
  16. },
  17. rules: {
  18. ...configPrettier.rules,
  19. ...pluginPrettier.configs.recommended.rules,
  20. 'no-debugger': 'off',
  21. 'no-unused-vars': [
  22. 'error',
  23. {
  24. argsIgnorePattern: '^_',
  25. varsIgnorePattern: '^_',
  26. },
  27. ],
  28. 'prettier/prettier': [
  29. 'error',
  30. {
  31. endOfLine: 'auto',
  32. },
  33. ],
  34. },
  35. },
  36. {
  37. files: ['**/*.?([cm])ts', '**/*.?([cm])tsx'],
  38. languageOptions: {
  39. parser: parserTypeScript,
  40. parserOptions: {
  41. sourceType: 'module',
  42. },
  43. },
  44. plugins: {
  45. '@typescript-eslint': pluginTypeScript,
  46. },
  47. rules: {
  48. ...pluginTypeScript.configs.strict.rules,
  49. '@typescript-eslint/ban-types': 'off',
  50. '@typescript-eslint/no-unused-vars': 'off',
  51. '@typescript-eslint/no-unused-expressions': 'off',
  52. '@typescript-eslint/no-invalid-void-type': 'off',
  53. '@typescript-eslint/no-redeclare': 'error',
  54. '@typescript-eslint/ban-ts-comment': 'off',
  55. '@typescript-eslint/prefer-ts-expect-error': 'off',
  56. '@typescript-eslint/no-explicit-any': 'off',
  57. '@typescript-eslint/prefer-as-const': 'warn',
  58. '@typescript-eslint/no-empty-function': 'off',
  59. '@typescript-eslint/no-empty-object-type': 'off',
  60. '@typescript-eslint/no-non-null-assertion': 'off',
  61. '@typescript-eslint/no-import-type-side-effects': 'error',
  62. '@typescript-eslint/explicit-module-boundary-types': 'off',
  63. '@typescript-eslint/consistent-type-imports': [
  64. 'error',
  65. { disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' },
  66. ],
  67. '@typescript-eslint/prefer-literal-enum-member': ['error', { allowBitwiseExpressions: true }],
  68. },
  69. },
  70. {
  71. files: ['**/*.d.ts'],
  72. rules: {
  73. 'eslint-comments/no-unlimited-disable': 'off',
  74. 'import/no-duplicates': 'off',
  75. 'unused-imports/no-unused-vars': 'off',
  76. },
  77. },
  78. {
  79. files: ['**/*.?([cm])js'],
  80. rules: {
  81. '@typescript-eslint/no-require-imports': 'off',
  82. '@typescript-eslint/no-var-requires': 'off',
  83. },
  84. },
  85. {
  86. files: ['**/*.vue'],
  87. languageOptions: {
  88. parser: parserVue,
  89. parserOptions: {
  90. ecmaFeatures: {
  91. jsx: true,
  92. },
  93. extraFileExtensions: ['.vue'],
  94. parser: parserTypeScript,
  95. sourceType: 'module',
  96. },
  97. },
  98. plugins: {
  99. vue: pluginVue,
  100. },
  101. processor: pluginVue.processors['.vue'],
  102. rules: {
  103. ...pluginVue.configs.base.rules,
  104. ...pluginVue.configs['vue3-essential'].rules,
  105. ...pluginVue.configs['vue3-recommended'].rules,
  106. 'no-undef': 'off',
  107. 'no-unused-vars': 'off',
  108. 'vue/no-v-html': 'off',
  109. 'vue/require-default-prop': 'off',
  110. 'vue/require-explicit-emits': 'off',
  111. 'vue/multi-word-component-names': 'off',
  112. 'vue/no-setup-props-reactivity-loss': 'off',
  113. 'vue/html-self-closing': [
  114. 'error',
  115. {
  116. html: {
  117. void: 'always',
  118. normal: 'always',
  119. component: 'always',
  120. },
  121. svg: 'always',
  122. math: 'always',
  123. },
  124. ],
  125. },
  126. },
  127. {
  128. files: ['**/*.vue', '**/*.?([cm])ts', '**/*.?([cm])tsx'],
  129. plugins: {
  130. import: pluginImport,
  131. 'unused-imports': unusedImports,
  132. },
  133. rules: {
  134. 'import/first': 'error',
  135. 'import/no-duplicates': 'error',
  136. 'import/order': [
  137. 'error',
  138. {
  139. groups: [
  140. 'builtin',
  141. 'external',
  142. 'internal',
  143. 'parent',
  144. 'sibling',
  145. 'index',
  146. 'object',
  147. 'type',
  148. ],
  149. pathGroups: [
  150. {
  151. pattern: 'vue',
  152. group: 'external',
  153. position: 'before',
  154. },
  155. {
  156. pattern: '@vue/**',
  157. group: 'external',
  158. position: 'before',
  159. },
  160. {
  161. pattern: 'ant-design-vue',
  162. group: 'internal',
  163. },
  164. ],
  165. pathGroupsExcludedImportTypes: ['type'],
  166. },
  167. ],
  168. 'unused-imports/no-unused-imports': 'error',
  169. // 如需保存时自动删除未引用代码,可注释掉该规则
  170. 'unused-imports/no-unused-vars': [
  171. 'warn',
  172. {
  173. vars: 'all',
  174. varsIgnorePattern: '^_',
  175. args: 'after-used',
  176. argsIgnorePattern: '^_',
  177. },
  178. ],
  179. },
  180. },
  181. {
  182. linterOptions: {
  183. reportUnusedDisableDirectives: 'off',
  184. },
  185. ignores: [
  186. 'src/assets/**',
  187. '*.sh',
  188. 'node_modules',
  189. '*.md',
  190. '*.woff',
  191. '*.ttf',
  192. '.vscode',
  193. '.idea',
  194. 'dist',
  195. '/public',
  196. '/docs',
  197. '.husky',
  198. '.local',
  199. '/bin',
  200. 'Dockerfile',
  201. ],
  202. },
  203. ]);