perfectionist.ts 3.2 KB

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