2024-05-19 21:20:42 +08:00
|
|
|
import type { Linter } from 'eslint';
|
|
|
|
|
2024-07-23 00:03:59 +08:00
|
|
|
import perfectionistPlugin from 'eslint-plugin-perfectionist';
|
2024-05-19 21:20:42 +08:00
|
|
|
|
2024-07-23 00:03:59 +08:00
|
|
|
export async function perfectionist(): Promise<Linter.FlatConfig[]> {
|
2024-05-19 21:20:42 +08:00
|
|
|
return [
|
2024-07-23 00:03:59 +08:00
|
|
|
perfectionistPlugin.configs['recommended-natural'],
|
2024-05-19 21:20:42 +08:00
|
|
|
{
|
|
|
|
rules: {
|
|
|
|
'perfectionist/sort-exports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
order: 'asc',
|
|
|
|
type: 'natural',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'perfectionist/sort-imports': [
|
|
|
|
'error',
|
|
|
|
{
|
2024-07-23 00:03:59 +08:00
|
|
|
customGroups: {
|
2024-05-19 21:20:42 +08:00
|
|
|
type: {
|
2024-06-08 19:49:06 +08:00
|
|
|
vben: 'vben',
|
|
|
|
vue: 'vue',
|
2024-05-19 21:20:42 +08:00
|
|
|
},
|
|
|
|
value: {
|
2024-07-08 22:30:19 +08:00
|
|
|
vben: ['@vben*', '@vben/**/**', '@vben-core/**/**'],
|
2024-06-08 19:49:06 +08:00
|
|
|
vue: ['vue', 'vue-*', '@vue*'],
|
2024-05-19 21:20:42 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
groups: [
|
2024-06-08 19:49:06 +08:00
|
|
|
['external-type', 'builtin-type', 'type'],
|
|
|
|
['parent-type', 'sibling-type', 'index-type'],
|
|
|
|
['internal-type'],
|
2024-05-19 21:20:42 +08:00
|
|
|
'builtin',
|
2024-06-08 19:49:06 +08:00
|
|
|
'vue',
|
2024-05-19 21:20:42 +08:00
|
|
|
'vben',
|
|
|
|
'external',
|
|
|
|
'internal',
|
|
|
|
['parent', 'sibling', 'index'],
|
2024-06-08 19:49:06 +08:00
|
|
|
'side-effect',
|
|
|
|
'side-effect-style',
|
2024-05-19 21:20:42 +08:00
|
|
|
'style',
|
|
|
|
'object',
|
|
|
|
'unknown',
|
|
|
|
],
|
2024-07-23 00:03:59 +08:00
|
|
|
internalPattern: ['#*', '#*/**'],
|
|
|
|
newlinesBetween: 'always',
|
2024-05-19 21:20:42 +08:00
|
|
|
order: 'asc',
|
|
|
|
type: 'natural',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'perfectionist/sort-named-exports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
order: 'asc',
|
|
|
|
type: 'natural',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'perfectionist/sort-objects': [
|
|
|
|
'error',
|
|
|
|
{
|
2024-07-23 00:03:59 +08:00
|
|
|
customGroups: {
|
2024-05-19 21:20:42 +08:00
|
|
|
items: 'items',
|
|
|
|
list: 'list',
|
|
|
|
children: 'children',
|
|
|
|
},
|
|
|
|
groups: ['unknown', 'items', 'list', 'children'],
|
2024-07-23 00:03:59 +08:00
|
|
|
ignorePattern: ['children'],
|
2024-05-19 21:20:42 +08:00
|
|
|
order: 'asc',
|
2024-07-23 00:03:59 +08:00
|
|
|
partitionByComment: 'Part:**',
|
2024-05-19 21:20:42 +08:00
|
|
|
type: 'natural',
|
|
|
|
},
|
|
|
|
],
|
2024-06-09 13:31:43 +08:00
|
|
|
'perfectionist/sort-vue-attributes': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
// Based on: https://vuejs.org/style-guide/rules-recommended.html#element-attribute-order
|
2024-07-23 00:03:59 +08:00
|
|
|
customGroups: {
|
2024-06-09 13:31:43 +08:00
|
|
|
/* eslint-disable perfectionist/sort-objects */
|
|
|
|
DEFINITION: '*(is|:is|v-is)',
|
|
|
|
LIST_RENDERING: 'v-for',
|
|
|
|
CONDITIONALS: 'v-*(else-if|if|else|show|cloak)',
|
|
|
|
RENDER_MODIFIERS: 'v-*(pre|once)',
|
|
|
|
GLOBAL: '*(:id|id)',
|
|
|
|
UNIQUE: '*(ref|key|:ref|:key)',
|
|
|
|
SLOT: '*(v-slot|slot)',
|
|
|
|
TWO_WAY_BINDING: '*(v-model|v-model:*)',
|
|
|
|
// OTHER_DIRECTIVES e.g. 'v-custom-directive'
|
|
|
|
EVENTS: '*(v-on|@*)',
|
|
|
|
CONTENT: 'v-*(html|text)',
|
|
|
|
/* eslint-enable perfectionist/sort-objects */
|
|
|
|
},
|
|
|
|
groups: [
|
|
|
|
'DEFINITION',
|
|
|
|
'LIST_RENDERING',
|
|
|
|
'CONDITIONALS',
|
|
|
|
'RENDER_MODIFIERS',
|
|
|
|
'GLOBAL',
|
|
|
|
'UNIQUE',
|
|
|
|
'SLOT',
|
|
|
|
'TWO_WAY_BINDING',
|
|
|
|
'unknown',
|
|
|
|
'EVENTS',
|
|
|
|
'CONTENT',
|
|
|
|
],
|
|
|
|
type: 'natural',
|
|
|
|
},
|
|
|
|
],
|
2024-05-19 21:20:42 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|