perf: format code with better style (#5283)

This commit is contained in:
Vben
2025-01-01 11:39:49 +08:00
committed by GitHub
parent 4d81b9d18d
commit 081d2aed23
288 changed files with 1805 additions and 2164 deletions

View File

@@ -10,6 +10,7 @@ export async function importPluginConfig(): Promise<Linter.Config[]> {
import: pluginImport,
},
rules: {
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'import/first': 'error',
'import/newline-after-import': 'error',
'import/no-duplicates': 'error',

View File

@@ -1,6 +1,5 @@
import type { Linter } from 'eslint';
// @ts-expect-error - no types
import js from '@eslint/js';
import pluginUnusedImports from 'eslint-plugin-unused-imports';
import globals from 'globals';

View File

@@ -1,8 +1,13 @@
import type { Linter } from 'eslint';
import perfectionistPlugin from 'eslint-plugin-perfectionist';
import { interopDefault } from '../util';
export async function perfectionist(): Promise<Linter.Config[]> {
const perfectionistPlugin = await interopDefault(
// @ts-expect-error - no types
import('eslint-plugin-perfectionist'),
);
return [
perfectionistPlugin.configs['recommended-natural'],
{
@@ -19,21 +24,28 @@ export async function perfectionist(): Promise<Linter.Config[]> {
{
customGroups: {
type: {
vben: 'vben',
vue: 'vue',
'vben-core-type': ['^@vben-core/.+'],
'vben-type': ['^@vben/.+'],
'vue-type': ['^vue$', '^vue-.+', '^@vue/.+'],
},
value: {
vben: ['@vben*', '@vben/**/**', '@vben-core/**/**'],
vue: ['vue', 'vue-*', '@vue*'],
vben: ['^@vben/.+'],
'vben-core': ['^@vben-core/.+'],
vue: ['^vue$', '^vue-.+', '^@vue/.+'],
},
},
environment: 'node',
groups: [
['external-type', 'builtin-type', 'type'],
'vue-type',
'vben-type',
'vben-core-type',
['parent-type', 'sibling-type', 'index-type'],
['internal-type'],
'builtin',
'vue',
'vben',
'vben-core',
'external',
'internal',
['parent', 'sibling', 'index'],
@@ -43,12 +55,13 @@ export async function perfectionist(): Promise<Linter.Config[]> {
'object',
'unknown',
],
internalPattern: ['#*', '#*/**'],
internalPattern: ['^#/.+'],
newlinesBetween: 'always',
order: 'asc',
type: 'natural',
},
],
'perfectionist/sort-modules': 'off',
'perfectionist/sort-named-exports': [
'error',
{
@@ -67,42 +80,6 @@ export async function perfectionist(): Promise<Linter.Config[]> {
groups: ['unknown', 'items', 'list', 'children'],
ignorePattern: ['children'],
order: 'asc',
partitionByComment: 'Part:**',
type: 'natural',
},
],
'perfectionist/sort-vue-attributes': [
'error',
{
// Based on: https://vuejs.org/style-guide/rules-recommended.html#element-attribute-order
customGroups: {
/* 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',
},
],

View File

@@ -2,7 +2,7 @@ export * from './constants';
export * from './date';
export * from './fs';
export * from './git';
export { add as gitAdd, getStagedFiles } from './git';
export { getStagedFiles, add as gitAdd } from './git';
export { generatorContentHash } from './hash';
export * from './monorepo';
export { toPosixPath } from './path';

View File

@@ -1,4 +1,6 @@
import ora, { type Ora } from 'ora';
import type { Ora } from 'ora';
import ora from 'ora';
interface SpinnerOptions {
failedText?: string;

View File

@@ -130,7 +130,6 @@ export default {
enterAnimationPlugin,
],
prefix: '',
safelist: ['dark'],
theme: {
container: {
center: true,
@@ -202,6 +201,7 @@ export default {
},
},
},
safelist: ['dark'],
} as Config;
function createColorsPalette(name: string) {

View File

@@ -10,11 +10,11 @@ import { minify } from 'html-minifier-terser';
const DEFAULT_PROVIDER = 'jspm.io';
type pluginOptions = {
type pluginOptions = GeneratorOptions & {
debug?: boolean;
defaultProvider?: 'esm.sh' | 'jsdelivr' | 'jspm.io';
importmap?: Array<{ name: string; range?: string }>;
} & GeneratorOptions;
};
// async function getLatestVersionOfShims() {
// const result = await fetch('https://ga.jspm.io/npm:es-module-shims');

View File

@@ -1,3 +1,5 @@
import type { PluginOption } from 'vite';
import fs from 'node:fs';
import fsp from 'node:fs/promises';
import { join } from 'node:path';
@@ -5,8 +7,6 @@ import { fileURLToPath } from 'node:url';
import { readPackageJSON } from '@vben/node-utils';
import { type PluginOption } from 'vite';
/**
* 用于生成将loading样式注入到项目中
* 为多app提供loading样式无需在每个 app -> index.html单独引入

View File

@@ -67,11 +67,11 @@ async function loadAndConvertEnv(
match = 'VITE_',
confFiles = getConfFiles(),
): Promise<
{
Partial<ApplicationPluginOptions> & {
appTitle: string;
base: string;
port: number;
} & Partial<ApplicationPluginOptions>
}
> {
const envConfig = await loadEnv(match, confFiles);