From c50d39999bf77e769c24d46e37d3780fe48e621b Mon Sep 17 00:00:00 2001 From: meteorlxy Date: Sat, 31 Aug 2024 15:59:53 +0800 Subject: [PATCH] style: fix lint errors --- docs/.vuepress/components/NpmBadge.vue | 20 ++++++------ docs/.vuepress/configs/head.ts | 1 + docs/.vuepress/configs/meta.ts | 6 ++-- docs/.vuepress/configs/navbar/en.ts | 11 ++++--- docs/.vuepress/configs/navbar/zh.ts | 11 ++++--- docs/.vuepress/configs/sidebar/en.ts | 4 +-- docs/.vuepress/configs/sidebar/zh.ts | 4 +-- .../cookbook/making-a-theme-extendable.md | 18 +++++------ .../cookbook/usage-of-client-config.md | 2 +- docs/advanced/plugin.md | 32 +++++++------------ docs/advanced/theme.md | 21 ++++++------ docs/guide/assets.md | 8 ++--- docs/reference/components.md | 2 +- docs/reference/node-api.md | 10 +++--- .../cookbook/making-a-theme-extendable.md | 18 +++++------ .../cookbook/usage-of-client-config.md | 2 +- docs/zh/advanced/plugin.md | 32 +++++++------------ docs/zh/advanced/theme.md | 21 ++++++------ docs/zh/guide/assets.md | 8 ++--- docs/zh/reference/components.md | 2 +- docs/zh/reference/node-api.md | 10 +++--- eslint.config.js | 5 +++ 22 files changed, 116 insertions(+), 132 deletions(-) diff --git a/docs/.vuepress/components/NpmBadge.vue b/docs/.vuepress/components/NpmBadge.vue index c9ff7be2..171047f3 100644 --- a/docs/.vuepress/components/NpmBadge.vue +++ b/docs/.vuepress/components/NpmBadge.vue @@ -1,17 +1,17 @@ + + ``` You can also access the helper by `$withBase` directly: diff --git a/docs/reference/components.md b/docs/reference/components.md index 3a045c39..0c772db7 100644 --- a/docs/reference/components.md +++ b/docs/reference/components.md @@ -13,7 +13,7 @@ interface AutoLinkConfig { /** * Pattern to determine if the link should be active, which has higher priority than `exact` */ - activeMatch?: string | RegExp + activeMatch?: RegExp | string /** * The `aria-label` attribute diff --git a/docs/reference/node-api.md b/docs/reference/node-api.md index 23cda854..37c79729 100644 --- a/docs/reference/node-api.md +++ b/docs/reference/node-api.md @@ -213,7 +213,7 @@ const homeSourceFile = app.dir.source('README.md') - Signature: ```ts -writeTemp(file: string, content: string): Promise +declare const writeTemp = (file: string, content: string) => Promise ``` - Parameters: @@ -250,7 +250,7 @@ import { foo } from '@temp/foo' - Signature: ```ts -init(): Promise +declare const init = () => Promise ``` - Details: @@ -265,7 +265,7 @@ init(): Promise - Signature: ```ts -prepare(): Promise +declare const prepare = () => Promise ``` - Details: @@ -280,7 +280,7 @@ prepare(): Promise - Signature: ```ts -build(): Promise +declare const build = () => Promise ``` - Details: @@ -298,7 +298,7 @@ build(): Promise - Signature: ```ts -dev(): Promise<() => Promise> +declare const dev = () => Promise<() => Promise> ``` - Details: diff --git a/docs/zh/advanced/cookbook/making-a-theme-extendable.md b/docs/zh/advanced/cookbook/making-a-theme-extendable.md index 1de74e6b..a3de57b3 100644 --- a/docs/zh/advanced/cookbook/making-a-theme-extendable.md +++ b/docs/zh/advanced/cookbook/making-a-theme-extendable.md @@ -34,16 +34,14 @@ import { getDirname, path } from 'vuepress/utils' const __dirname = getDirname(import.meta.url) -export const fooTheme = (options): Theme => { - return { - name: 'vuepress-theme-foo', - alias: { - // 为可替换的组件设置别名 - '@theme/Navbar.vue': path.resolve(__dirname, 'components/Navbar.vue'), - '@theme/Sidebar.vue': path.resolve(__dirname, 'components/Sidebar.vue'), - }, - } -} +export const fooTheme = (options): Theme => ({ + name: 'vuepress-theme-foo', + alias: { + // 为可替换的组件设置别名 + '@theme/Navbar.vue': path.resolve(__dirname, 'components/Navbar.vue'), + '@theme/Sidebar.vue': path.resolve(__dirname, 'components/Sidebar.vue'), + }, +}) ``` 然后,在你的主题中通过别名来使用这些组件: diff --git a/docs/zh/advanced/cookbook/usage-of-client-config.md b/docs/zh/advanced/cookbook/usage-of-client-config.md index 25bdc41c..26dab64b 100644 --- a/docs/zh/advanced/cookbook/usage-of-client-config.md +++ b/docs/zh/advanced/cookbook/usage-of-client-config.md @@ -130,8 +130,8 @@ export default defineClientConfig({ 使用不支持 SSR 的功能的另一种方式就是将他们放在 [onMounted](https://staging-cn.vuejs.org/api/composition-api-lifecycle.html#onmounted) Hook 中: ```ts -import { defineClientConfig } from 'vuepress/client' import { onMounted } from 'vue' +import { defineClientConfig } from 'vuepress/client' export default defineClientConfig({ setup() { diff --git a/docs/zh/advanced/plugin.md b/docs/zh/advanced/plugin.md index 8f53a186..36a095bb 100644 --- a/docs/zh/advanced/plugin.md +++ b/docs/zh/advanced/plugin.md @@ -18,32 +18,24 @@ const fooPlugin = { 插件还可以是一个接收 [App 实例](../reference/node-api.md#app) 作为参数,且返回值为 _插件对象_ 的函数,称之为 _插件函数_ : ```ts -const barPlugin = (app) => { - return { - name: 'vuepress-plugin-bar', - // ... - } -} +const barPlugin = (app) => ({ + name: 'vuepress-plugin-bar', + // ... +}) ``` 插件通常需要允许用户传入配置,因此我们一般都会提供给用户一个函数来接收配置,然后将 _插件对象_ 或者 _插件函数_ 作为返回值。于是,你的插件应该转换成这样的形式: ```ts -const fooPlugin = (options) => { - return { - name: 'vuepress-plugin-foo', - // ... - } -} +const fooPlugin = (options) => ({ + name: 'vuepress-plugin-foo', + // ... +}) -const barPlugin = (options) => { - return (app) => { - return { - name: 'vuepress-plugin-bar', - // ... - } - } -} +const barPlugin = (options) => (app) => ({ + name: 'vuepress-plugin-bar', + // ... +}) ``` ## 发布到 NPM diff --git a/docs/zh/advanced/theme.md b/docs/zh/advanced/theme.md index fcb3c6d7..239b6f68 100644 --- a/docs/zh/advanced/theme.md +++ b/docs/zh/advanced/theme.md @@ -13,9 +13,9 @@ import { getDirname, path } from 'vuepress/utils' const __dirname = getDirname(import.meta.url) -const fooTheme = (options) => { +const fooTheme = (options) => // 返回一个主题对象 - return { + ({ name: 'vuepress-theme-foo', // 主题的客户端配置文件的路径 @@ -32,18 +32,15 @@ const fooTheme = (options) => { ], // 其他的插件 API 也都可用 - } -} + }) -const barTheme = (options) => { +const barTheme = + (options) => // 返回一个主题函数 - return (app) => { - return { - name: 'vuepress-theme-bar', - // ... - } - } -} + (app) => ({ + name: 'vuepress-theme-bar', + // ... + }) ``` 然后,创建主题的客户端配置文件 `client.js` : diff --git a/docs/zh/guide/assets.md b/docs/zh/guide/assets.md index 52ee28b2..611cda86 100644 --- a/docs/zh/guide/assets.md +++ b/docs/zh/guide/assets.md @@ -71,16 +71,16 @@ 然而,有些情况下,你可能会有一些指向 Public 文件的动态路径,尤其是在你开发一个自定义主题的时候。在这种情况下, `base` 无法被自动处理。为了解决这个问题,VuePress 提供了 [withBase](../reference/client-api.md#withbase) 工具函数,它可以帮助你添加 `base` 前缀: ```vue - - + + ``` 你也可以通过 `$withBase` 来直接使用这个工具函数: diff --git a/docs/zh/reference/components.md b/docs/zh/reference/components.md index 95f790d2..5b4b9c96 100644 --- a/docs/zh/reference/components.md +++ b/docs/zh/reference/components.md @@ -13,7 +13,7 @@ interface AutoLinkConfig { /** * 判断该链接是否被激活的模式,优先级高于 `exact` */ - activeMatch?: string | RegExp + activeMatch?: RegExp | string /** * `aria-label` 属性 diff --git a/docs/zh/reference/node-api.md b/docs/zh/reference/node-api.md index 867b3d09..ceb6d412 100644 --- a/docs/zh/reference/node-api.md +++ b/docs/zh/reference/node-api.md @@ -213,7 +213,7 @@ const homeSourceFile = app.dir.source('README.md') - 函数签名: ```ts -writeTemp(file: string, content: string): Promise +declare const writeTemp = (file: string, content: string) => Promise ``` - 参数: @@ -250,7 +250,7 @@ import { foo } from '@temp/foo' - 函数签名: ```ts -init(): Promise +declare const init = () => Promise ``` - 详情: @@ -265,7 +265,7 @@ init(): Promise - 函数签名: ```ts -prepare(): Promise +declare const prepare = () => Promise ``` - 详情: @@ -280,7 +280,7 @@ prepare(): Promise - 函数签名: ```ts -build(): Promise +declare const build = () => Promise ``` - 详情: @@ -297,7 +297,7 @@ build(): Promise - 函数签名: ```ts -dev(): Promise<() => Promise> +declare const dev = () => Promise<() => Promise> ``` - 详情: diff --git a/eslint.config.js b/eslint.config.js index 31cefe06..d20785d5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,6 +1,11 @@ import { vuepress } from 'eslint-config-vuepress' export default vuepress({ + ignores: [ + // the intended js parsing error could not be disabled, so we have to ignore them + 'docs/guide/markdown.md', + 'docs/zh/guide/markdown.md', + ], vue: { overrides: { 'no-useless-assignment': 'off', // TODO: false positive in vue sfc