admin-vben5/internal/lint-configs/eslint-config/src/configs/perfectionist.ts

113 lines
3.2 KiB
TypeScript
Raw Normal View History

2024-05-19 21:20:42 +08:00
import type { Linter } from 'eslint';
import perfectionistPlugin from 'eslint-plugin-perfectionist';
2024-05-19 21:20:42 +08:00
export async function perfectionist(): Promise<Linter.Config[]> {
2024-05-19 21:20:42 +08:00
return [
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',
{
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: {
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',
],
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',
{
customGroups: {
2024-05-19 21:20:42 +08:00
items: 'items',
list: 'list',
children: 'children',
},
groups: ['unknown', 'items', 'list', 'children'],
ignorePattern: ['children'],
2024-05-19 21:20:42 +08:00
order: 'asc',
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
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
},
},
];
}