perfectionist.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import type { Linter } from 'eslint';
  2. export async function perfectionist(): Promise<Linter.FlatConfig[]> {
  3. const [perfectionistNatural] = await Promise.all([
  4. // @ts-expect-error - no types
  5. import('eslint-plugin-perfectionist/configs/recommended-natural'),
  6. ] as const);
  7. return [
  8. perfectionistNatural,
  9. {
  10. rules: {
  11. 'perfectionist/sort-exports': [
  12. 'error',
  13. {
  14. order: 'asc',
  15. type: 'natural',
  16. },
  17. ],
  18. 'perfectionist/sort-imports': [
  19. 'error',
  20. {
  21. 'custom-groups': {
  22. type: {
  23. vben: 'vben',
  24. vue: 'vue',
  25. },
  26. value: {
  27. vben: ['@vben*', '@vben/*', '@vben-core/*'],
  28. vue: ['vue', 'vue-*', '@vue*'],
  29. },
  30. },
  31. groups: [
  32. ['external-type', 'builtin-type', 'type'],
  33. ['parent-type', 'sibling-type', 'index-type'],
  34. ['internal-type'],
  35. 'builtin',
  36. 'vue',
  37. 'vben',
  38. 'external',
  39. 'internal',
  40. ['parent', 'sibling', 'index'],
  41. 'side-effect',
  42. 'side-effect-style',
  43. 'style',
  44. 'object',
  45. 'unknown',
  46. ],
  47. 'internal-pattern': ['#*', '#*/**'],
  48. 'newlines-between': 'always',
  49. order: 'asc',
  50. type: 'natural',
  51. },
  52. ],
  53. 'perfectionist/sort-named-exports': [
  54. 'error',
  55. {
  56. order: 'asc',
  57. type: 'natural',
  58. },
  59. ],
  60. 'perfectionist/sort-objects': [
  61. 'error',
  62. {
  63. 'custom-groups': {
  64. items: 'items',
  65. list: 'list',
  66. children: 'children',
  67. },
  68. groups: ['unknown', 'items', 'list', 'children'],
  69. 'ignore-pattern': ['children'],
  70. order: 'asc',
  71. 'partition-by-comment': 'Part:**',
  72. type: 'natural',
  73. },
  74. ],
  75. 'perfectionist/sort-vue-attributes': [
  76. 'error',
  77. {
  78. // Based on: https://vuejs.org/style-guide/rules-recommended.html#element-attribute-order
  79. 'custom-groups': {
  80. /* eslint-disable perfectionist/sort-objects */
  81. DEFINITION: '*(is|:is|v-is)',
  82. LIST_RENDERING: 'v-for',
  83. CONDITIONALS: 'v-*(else-if|if|else|show|cloak)',
  84. RENDER_MODIFIERS: 'v-*(pre|once)',
  85. GLOBAL: '*(:id|id)',
  86. UNIQUE: '*(ref|key|:ref|:key)',
  87. SLOT: '*(v-slot|slot)',
  88. TWO_WAY_BINDING: '*(v-model|v-model:*)',
  89. // OTHER_DIRECTIVES e.g. 'v-custom-directive'
  90. EVENTS: '*(v-on|@*)',
  91. CONTENT: 'v-*(html|text)',
  92. /* eslint-enable perfectionist/sort-objects */
  93. },
  94. groups: [
  95. 'DEFINITION',
  96. 'LIST_RENDERING',
  97. 'CONDITIONALS',
  98. 'RENDER_MODIFIERS',
  99. 'GLOBAL',
  100. 'UNIQUE',
  101. 'SLOT',
  102. 'TWO_WAY_BINDING',
  103. 'unknown',
  104. 'EVENTS',
  105. 'CONTENT',
  106. ],
  107. type: 'natural',
  108. },
  109. ],
  110. },
  111. },
  112. ];
  113. }