From 88908d13c20db9cdca4c682f30cf0e14ee2b39b6 Mon Sep 17 00:00:00 2001 From: meteorlxy Date: Wed, 30 Aug 2023 18:46:23 +0800 Subject: [PATCH] style: format code --- .../src/client/components/Docsearch.ts | 11 +---- .../src/node/externalLinkIconPlugin.ts | 2 +- .../plugin-theme-data/src/client/config.ts | 7 +--- .../src/client/components/Navbar.vue | 4 +- .../client/components/ToggleSidebarButton.vue | 4 +- package.json | 1 + .../bundler-vite/src/resolveViteConfig.ts | 3 +- .../src/build/resolvePageClientFilesMeta.ts | 2 +- packages/bundler-webpack/src/types.webpack.ts | 26 ++++++------ packages/client/src/composables/layouts.ts | 3 +- packages/client/src/composables/pageData.ts | 3 +- packages/client/src/composables/pageLayout.ts | 8 +--- packages/client/src/resolvers.ts | 21 +++++----- packages/client/src/router.ts | 2 +- packages/client/src/setupGlobalComputed.ts | 41 ++++++++++--------- packages/core/src/types/pluginApi/hooks.ts | 8 ++-- packages/shared/src/types/page.ts | 4 +- packages/utils/src/withSpinner.ts | 3 +- 18 files changed, 72 insertions(+), 81 deletions(-) diff --git a/ecosystem/plugin-docsearch/src/client/components/Docsearch.ts b/ecosystem/plugin-docsearch/src/client/components/Docsearch.ts index 70cf7c316c..f03080cb63 100644 --- a/ecosystem/plugin-docsearch/src/client/components/Docsearch.ts +++ b/ecosystem/plugin-docsearch/src/client/components/Docsearch.ts @@ -1,13 +1,6 @@ import { usePageLang, useRouteLocale } from '@vuepress/client' -import { - computed, - defineComponent, - h, - onMounted, - type PropType, - ref, - watch, -} from 'vue' +import type { PropType } from 'vue' +import { computed, defineComponent, h, onMounted, ref, watch } from 'vue' import type { DocsearchOptions } from '../../shared/index.js' import { useDocsearchHotkeyListener, diff --git a/ecosystem/plugin-external-link-icon/src/node/externalLinkIconPlugin.ts b/ecosystem/plugin-external-link-icon/src/node/externalLinkIconPlugin.ts index 9b29184998..a05f602f91 100644 --- a/ecosystem/plugin-external-link-icon/src/node/externalLinkIconPlugin.ts +++ b/ecosystem/plugin-external-link-icon/src/node/externalLinkIconPlugin.ts @@ -8,7 +8,7 @@ const __dirname = getDirname(import.meta.url) /** * Options for @vuepress/plugin-external-link-icon */ -export type ExternalLinkIconPluginOptions = { +export interface ExternalLinkIconPluginOptions { /** * Locales config for external link icon */ diff --git a/ecosystem/plugin-theme-data/src/client/config.ts b/ecosystem/plugin-theme-data/src/client/config.ts index 0110a885ca..76245fb5c8 100644 --- a/ecosystem/plugin-theme-data/src/client/config.ts +++ b/ecosystem/plugin-theme-data/src/client/config.ts @@ -1,9 +1,6 @@ import { setupDevtoolsPlugin } from '@vue/devtools-api' -import { - defineClientConfig, - type RouteLocaleRef, - routeLocaleSymbol, -} from '@vuepress/client' +import type { RouteLocaleRef } from '@vuepress/client' +import { defineClientConfig, routeLocaleSymbol } from '@vuepress/client' import { computed } from 'vue' import { resolveThemeLocaleData, diff --git a/ecosystem/theme-default/src/client/components/Navbar.vue b/ecosystem/theme-default/src/client/components/Navbar.vue index fbf5f5ab3f..bf32a8c86b 100644 --- a/ecosystem/theme-default/src/client/components/Navbar.vue +++ b/ecosystem/theme-default/src/client/components/Navbar.vue @@ -10,9 +10,7 @@ import { useUpdateDeviceStatus, } from '../composables/index.js' -defineEmits<{ - (e: 'toggle-sidebar'): void -}>() +defineEmits<(e: 'toggle-sidebar') => void>() defineSlots<{ before?: (props: Record) => any diff --git a/ecosystem/theme-default/src/client/components/ToggleSidebarButton.vue b/ecosystem/theme-default/src/client/components/ToggleSidebarButton.vue index dbbf040726..917578b872 100644 --- a/ecosystem/theme-default/src/client/components/ToggleSidebarButton.vue +++ b/ecosystem/theme-default/src/client/components/ToggleSidebarButton.vue @@ -1,9 +1,7 @@ diff --git a/package.json b/package.json index 61275b1757..ca33e3905b 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "docs:serve": "pnpm --filter=docs docs:serve", "format": "prettier --write .", "lint": "eslint --ext .cjs,.js,.ts,.vue . && prettier --check .", + "lint:fix": "eslint --fix --ext .cjs,.js,.ts,.vue . && prettier --write .", "prepare": "husky install", "release": "pnpm release:check && pnpm release:version && pnpm release:publish", "release:changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", diff --git a/packages/bundler-vite/src/resolveViteConfig.ts b/packages/bundler-vite/src/resolveViteConfig.ts index 2c0e2784ec..48de09a396 100644 --- a/packages/bundler-vite/src/resolveViteConfig.ts +++ b/packages/bundler-vite/src/resolveViteConfig.ts @@ -1,6 +1,7 @@ import { default as vuePlugin } from '@vitejs/plugin-vue' import type { App } from '@vuepress/core' -import { type InlineConfig, mergeConfig } from 'vite' +import type { InlineConfig } from 'vite' +import { mergeConfig } from 'vite' import { constantsReplacementPlugin, mainPlugin, diff --git a/packages/bundler-webpack/src/build/resolvePageClientFilesMeta.ts b/packages/bundler-webpack/src/build/resolvePageClientFilesMeta.ts index d8ed43cbb1..05d19a47de 100644 --- a/packages/bundler-webpack/src/build/resolvePageClientFilesMeta.ts +++ b/packages/bundler-webpack/src/build/resolvePageClientFilesMeta.ts @@ -10,7 +10,7 @@ export const resolvePageClientFilesMeta = ({ moduleRequests: string[] moduleFilesMetaMap: ModuleFilesMetaMap }): FileMeta[] => { - const files: Set = new Set() + const files = new Set() moduleRequests.forEach((request) => { moduleFilesMetaMap[request]?.forEach((file) => files.add(file)) }) diff --git a/packages/bundler-webpack/src/types.webpack.ts b/packages/bundler-webpack/src/types.webpack.ts index 063b3b9f7c..d04f90f60c 100644 --- a/packages/bundler-webpack/src/types.webpack.ts +++ b/packages/bundler-webpack/src/types.webpack.ts @@ -6,18 +6,18 @@ import type { Compiler, ModuleOptions } from 'webpack' export interface StatsToJsonOutput { _showErrors: boolean _showWarnings: boolean - assets?: Array<{ - chunks: Array + assets?: { + chunks: (number | string)[] chunkNames: string[] emitted: boolean isOverSizeLimit?: boolean name: string size: number - }> + }[] assetsByChunkName?: Record builtAt?: number - children?: Array - chunks?: Array<{ + children?: (StatsToJsonOutput & { name?: string })[] + chunks?: { children: number[] childrenByOrder: Record entry: boolean @@ -28,7 +28,7 @@ export interface StatsToJsonOutput { initial: boolean modules?: FnModules[] names: string[] - origins?: Array<{ + origins?: { moduleId?: string | number module: string moduleIdentifier: string @@ -36,14 +36,14 @@ export interface StatsToJsonOutput { loc: string request: string reasons: string[] - }> + }[] parents: number[] reason?: string recorded?: boolean rendered: boolean size: number siblings: number[] - }> + }[] entrypoints?: Record errors: string[] env?: Record @@ -64,7 +64,7 @@ export interface FnModules { assets?: string[] built: boolean cacheable: boolean - chunks: Array + chunks: (number | string)[] depth?: number errors: number failed: boolean @@ -76,12 +76,12 @@ export interface FnModules { issuer: string | undefined issuerId: number | string | undefined issuerName: string | undefined - issuerPath: Array<{ + issuerPath: { id: number | string identifier: string name: string profile: any // TODO - }> + }[] modules: FnModules[] name: string optimizationBailout?: string @@ -98,12 +98,12 @@ export interface FnModules { export interface ChunkGroup { assets: { name: string }[] - chunks: Array + chunks: (number | string)[] children: Record< string, { assets: string[] - chunks: Array + chunks: (number | string)[] name: string } > diff --git a/packages/client/src/composables/layouts.ts b/packages/client/src/composables/layouts.ts index 5a91197191..187d4ddf1f 100644 --- a/packages/client/src/composables/layouts.ts +++ b/packages/client/src/composables/layouts.ts @@ -1,4 +1,5 @@ -import { type ComputedRef, inject, type InjectionKey } from 'vue' +import type { ComputedRef, InjectionKey } from 'vue' +import { inject } from 'vue' import type { Layouts } from '../types/index.js' /** diff --git a/packages/client/src/composables/pageData.ts b/packages/client/src/composables/pageData.ts index c7e962e268..3f96a00659 100644 --- a/packages/client/src/composables/pageData.ts +++ b/packages/client/src/composables/pageData.ts @@ -1,5 +1,6 @@ import type { PageData } from '@vuepress/shared' -import { inject, type InjectionKey, readonly, type Ref } from 'vue' +import type { InjectionKey, Ref } from 'vue' +import { inject, readonly } from 'vue' export type { PageData } diff --git a/packages/client/src/composables/pageLayout.ts b/packages/client/src/composables/pageLayout.ts index 0ac2d1aeac..9c40423703 100644 --- a/packages/client/src/composables/pageLayout.ts +++ b/packages/client/src/composables/pageLayout.ts @@ -1,9 +1,5 @@ -import { - type Component, - type ComputedRef, - inject, - type InjectionKey, -} from 'vue' +import type { Component, ComputedRef, InjectionKey } from 'vue' +import { inject } from 'vue' /** * Ref wrapper of `PageLayout` diff --git a/packages/client/src/resolvers.ts b/packages/client/src/resolvers.ts index af279e9727..f8c70f3836 100644 --- a/packages/client/src/resolvers.ts +++ b/packages/client/src/resolvers.ts @@ -6,18 +6,17 @@ import { } from '@vuepress/shared' import type { Component } from 'vue' import { reactive } from 'vue' -import { - type PageData, - pageDataEmpty, - type PageFrontmatter, - type PageHead, - type PageHeadTitle, - type PageLang, - pagesData, - type RouteLocale, - type SiteData, - type SiteLocaleData, +import type { + PageData, + PageFrontmatter, + PageHead, + PageHeadTitle, + PageLang, + RouteLocale, + SiteData, + SiteLocaleData, } from './composables/index.js' +import { pageDataEmpty, pagesData } from './composables/index.js' import { LAYOUT_NAME_DEFAULT, LAYOUT_NAME_NOT_FOUND } from './constants.js' import type { ClientConfig, Layouts } from './types/index.js' diff --git a/packages/client/src/router.ts b/packages/client/src/router.ts index 8b399c52b2..d6045df4e7 100644 --- a/packages/client/src/router.ts +++ b/packages/client/src/router.ts @@ -1,10 +1,10 @@ import { pagesComponents } from '@internal/pagesComponents' import { removeEndingSlash } from '@vuepress/shared' +import type { Router } from 'vue-router' import { createMemoryHistory, createRouter, createWebHistory, - type Router, START_LOCATION, } from 'vue-router' import type { PageData } from './composables/index.js' diff --git a/packages/client/src/setupGlobalComputed.ts b/packages/client/src/setupGlobalComputed.ts index 5a47b2802d..49c4fa6901 100644 --- a/packages/client/src/setupGlobalComputed.ts +++ b/packages/client/src/setupGlobalComputed.ts @@ -1,35 +1,38 @@ import { computedEager, computedWithControl } from '@vueuse/core' -import { type App, computed } from 'vue' +import type { App } from 'vue' +import { computed } from 'vue' import type { Router } from 'vue-router' +import type { + LayoutsRef, + PageData, + PageDataRef, + PageFrontmatter, + PageFrontmatterRef, + PageHead, + PageHeadRef, + PageHeadTitle, + PageHeadTitleRef, + PageLang, + PageLangRef, + PageLayoutRef, + RouteLocale, + RouteLocaleRef, + SiteData, + SiteDataRef, + SiteLocaleData, + SiteLocaleDataRef, +} from './composables/index.js' import { - type LayoutsRef, layoutsSymbol, - type PageData, - type PageDataRef, pageDataSymbol, - type PageFrontmatter, - type PageFrontmatterRef, pageFrontmatterSymbol, - type PageHead, - type PageHeadRef, pageHeadSymbol, - type PageHeadTitle, - type PageHeadTitleRef, pageHeadTitleSymbol, - type PageLang, - type PageLangRef, pageLangSymbol, - type PageLayoutRef, pageLayoutSymbol, pagesData, - type RouteLocale, - type RouteLocaleRef, routeLocaleSymbol, - type SiteData, siteData, - type SiteDataRef, - type SiteLocaleData, - type SiteLocaleDataRef, siteLocaleDataSymbol, } from './composables/index.js' import { withBase } from './helpers/index.js' diff --git a/packages/core/src/types/pluginApi/hooks.ts b/packages/core/src/types/pluginApi/hooks.ts index c6d0c1f6c8..4e88851256 100644 --- a/packages/core/src/types/pluginApi/hooks.ts +++ b/packages/core/src/types/pluginApi/hooks.ts @@ -4,10 +4,12 @@ import type { Page, PageOptions } from '../page.js' // util type type PromiseOrNot = Promise | T -type Closable = { close(): void } +interface Closable { + close(): void +} // base hook type -export type Hook< +export interface Hook< Exposed, Normalized = Exposed, Result = Normalized extends (...args: any) => infer U @@ -15,7 +17,7 @@ export type Hook< ? V : U : void, -> = { +> { exposed: Exposed normalized: Normalized result: Result diff --git a/packages/shared/src/types/page.ts b/packages/shared/src/types/page.ts index c82720bfd4..4ffecb23e8 100644 --- a/packages/shared/src/types/page.ts +++ b/packages/shared/src/types/page.ts @@ -4,9 +4,9 @@ import type { HeadConfig } from './head.js' /** * Base type of vuepress page */ -export type PageBase< +export interface PageBase< ExtraPageFrontmatter extends Record = Record, -> = { +> { /** * Identifier of the page * diff --git a/packages/utils/src/withSpinner.ts b/packages/utils/src/withSpinner.ts index 5d42f0a94a..fee698e911 100644 --- a/packages/utils/src/withSpinner.ts +++ b/packages/utils/src/withSpinner.ts @@ -1,5 +1,6 @@ import process from 'node:process' -import ora, { type Ora } from 'ora' +import type { Ora } from 'ora' +import ora from 'ora' import { formatMs } from './formatMs.js' export const withSpinner =