Skip to content

Commit c50d399

Browse files
committed
style: fix lint errors
1 parent f204afd commit c50d399

22 files changed

+116
-132
lines changed

docs/.vuepress/components/NpmBadge.vue

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<script setup lang="ts">
22
import { computed } from 'vue'
33
4-
const props = defineProps({
5-
package: {
6-
type: String,
7-
required: true,
4+
const props = withDefaults(
5+
defineProps<{
6+
/** package name */
7+
package: string
8+
/** dist-tag to use */
9+
distTag?: string
10+
}>(),
11+
{
12+
distTag: 'next',
813
},
9-
distTag: {
10-
type: String,
11-
required: false,
12-
default: 'next',
13-
},
14-
})
14+
)
1515
1616
const badgeLink = computed(
1717
() => `https://www.npmjs.com/package/${props.package}`,

docs/.vuepress/configs/head.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { HeadConfig } from 'vuepress/core'
22

3+
// eslint-disable-next-line @typescript-eslint/naming-convention
34
export const head: HeadConfig[] = [
45
[
56
'link',

docs/.vuepress/configs/meta.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { fs } from 'vuepress/utils'
33

44
const require = createRequire(import.meta.url)
55

6-
export const version = fs.readJsonSync(
7-
require.resolve('vuepress/package.json'),
6+
export const VERSION = (
7+
fs.readJsonSync(require.resolve('vuepress/package.json')) as {
8+
version: string
9+
}
810
).version

docs/.vuepress/configs/navbar/en.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { NavbarConfig } from '@vuepress/theme-default'
2-
import { version } from '../meta.js'
1+
import type { NavbarOptions } from '@vuepress/theme-default'
2+
import { VERSION } from '../meta.js'
33

4-
export const navbarEn: NavbarConfig = [
4+
export const navbarEn: NavbarOptions = [
55
{
66
text: 'Guide',
77
children: [
@@ -97,7 +97,7 @@ export const navbarEn: NavbarConfig = [
9797
],
9898
},
9999
{
100-
text: `v${version}`,
100+
text: `v${VERSION}`,
101101
children: [
102102
{
103103
text: 'Changelog',
@@ -113,4 +113,5 @@ export const navbarEn: NavbarConfig = [
113113
},
114114
],
115115
},
116-
]
116+
// TODO: remove the type assertion
117+
] as NavbarOptions

docs/.vuepress/configs/navbar/zh.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { NavbarConfig } from '@vuepress/theme-default'
2-
import { version } from '../meta.js'
1+
import type { NavbarOptions } from '@vuepress/theme-default'
2+
import { VERSION } from '../meta.js'
33

4-
export const navbarZh: NavbarConfig = [
4+
export const navbarZh: NavbarOptions = [
55
{
66
text: '指南',
77
children: [
@@ -93,7 +93,7 @@ export const navbarZh: NavbarConfig = [
9393
],
9494
},
9595
{
96-
text: `v${version}`,
96+
text: `v${VERSION}`,
9797
children: [
9898
{
9999
text: '更新日志',
@@ -109,4 +109,5 @@ export const navbarZh: NavbarConfig = [
109109
},
110110
],
111111
},
112-
]
112+
// TODO: remove the type assertion
113+
] as NavbarOptions

docs/.vuepress/configs/sidebar/en.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { SidebarConfig } from '@vuepress/theme-default'
1+
import type { SidebarOptions } from '@vuepress/theme-default'
22

3-
export const sidebarEn: SidebarConfig = {
3+
export const sidebarEn: SidebarOptions = {
44
'/guide/': [
55
{
66
text: 'Guide',

docs/.vuepress/configs/sidebar/zh.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { SidebarConfig } from '@vuepress/theme-default'
1+
import type { SidebarOptions } from '@vuepress/theme-default'
22

3-
export const sidebarZh: SidebarConfig = {
3+
export const sidebarZh: SidebarOptions = {
44
'/zh/guide/': [
55
{
66
text: '指南',

docs/advanced/cookbook/making-a-theme-extendable.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ import { getDirname } from 'vuepress/utils'
3434

3535
const __dirname = getDirname(import.meta.url)
3636

37-
export const fooTheme = (options): Theme => {
38-
return {
39-
name: 'vuepress-theme-foo',
40-
alias: {
41-
// set alias for replaceable components
42-
'@theme/Navbar.vue': path.resolve(__dirname, 'components/Navbar.vue'),
43-
'@theme/Sidebar.vue': path.resolve(__dirname, 'components/Sidebar.vue'),
44-
},
45-
}
46-
}
37+
export const fooTheme = (options): Theme => ({
38+
name: 'vuepress-theme-foo',
39+
alias: {
40+
// set alias for replaceable components
41+
'@theme/Navbar.vue': path.resolve(__dirname, 'components/Navbar.vue'),
42+
'@theme/Sidebar.vue': path.resolve(__dirname, 'components/Sidebar.vue'),
43+
},
44+
})
4745
```
4846

4947
Next, use those components via aliases in your theme:

docs/advanced/cookbook/usage-of-client-config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ In the `setup` function, the [`__VUEPRESS_SSR__`](../../reference/client-api.md#
130130
Another way to use non-ssr-friendly features is to put them inside the [onMounted](https://vuejs.org/api/composition-api-lifecycle.html#onmounted) hook:
131131

132132
```ts
133-
import { defineClientConfig } from 'vuepress/client'
134133
import { onMounted } from 'vue'
134+
import { defineClientConfig } from 'vuepress/client'
135135

136136
export default defineClientConfig({
137137
setup() {

docs/advanced/plugin.md

+12-20
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,24 @@ const fooPlugin = {
1818
A plugin could also be a function that receives the [app instance](../reference/node-api.md#app) as the param and returns a _Plugin Object_, which is called a _Plugin Function_:
1919

2020
```ts
21-
const barPlugin = (app) => {
22-
return {
23-
name: 'vuepress-plugin-bar',
24-
// ...
25-
}
26-
}
21+
const barPlugin = (app) => ({
22+
name: 'vuepress-plugin-bar',
23+
// ...
24+
})
2725
```
2826

2927
A plugin usually needs to allow user options, so we typically provide users with a function to receive options, and returns a _Plugin Object_ or a _Plugin Function_. Then your plugin should be converted like this:
3028

3129
```ts
32-
const fooPlugin = (options) => {
33-
return {
34-
name: 'vuepress-plugin-foo',
35-
// ...
36-
}
37-
}
30+
const fooPlugin = (options) => ({
31+
name: 'vuepress-plugin-foo',
32+
// ...
33+
})
3834

39-
const barPlugin = (options) => {
40-
return (app) => {
41-
return {
42-
name: 'vuepress-plugin-bar',
43-
// ...
44-
}
45-
}
46-
}
35+
const barPlugin = (options) => (app) => ({
36+
name: 'vuepress-plugin-bar',
37+
// ...
38+
})
4739
```
4840

4941
## Publish to NPM

docs/advanced/theme.md

+9-12
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { getDirname, path } from 'vuepress/utils'
1313

1414
const __dirname = getDirname(import.meta.url)
1515

16-
const fooTheme = (options) => {
16+
const fooTheme = (options) =>
1717
// returns a theme object
18-
return {
18+
({
1919
name: 'vuepress-theme-foo',
2020

2121
// path to the client config of your theme
@@ -32,18 +32,15 @@ const fooTheme = (options) => {
3232
],
3333

3434
// other plugin APIs are also available
35-
}
36-
}
35+
})
3736

38-
const barTheme = (options) => {
37+
const barTheme =
38+
(options) =>
3939
// returns a theme function
40-
return (app) => {
41-
return {
42-
name: 'vuepress-theme-bar',
43-
// ...
44-
}
45-
}
46-
}
40+
(app) => ({
41+
name: 'vuepress-theme-bar',
42+
// ...
43+
})
4744
```
4845

4946
Then, create theme's client config file `client.js` :

docs/guide/assets.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ When using [webpack bundler](../reference/bundler/webpack.md), you need to set [
7171
However, sometimes you may have some dynamical links referencing public files, especially when you are authoring a custom theme. In such case, the `base` could not be handled automatically. To help with that, VuePress provides a [withBase](../reference/client-api.md#withbase) helper to prepend `base` for you:
7272

7373
```vue
74-
<template>
75-
<img :src="withBase(logoPath)" />
76-
</template>
77-
7874
<script setup>
7975
import { ref } from 'vue'
8076
import { withBase } from 'vuepress/client'
8177
8278
const logoPath = ref('/images/hero.png')
8379
</script>
80+
81+
<template>
82+
<img :src="withBase(logoPath)" />
83+
</template>
8484
```
8585

8686
You can also access the helper by `$withBase` directly:

docs/reference/components.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface AutoLinkConfig {
1313
/**
1414
* Pattern to determine if the link should be active, which has higher priority than `exact`
1515
*/
16-
activeMatch?: string | RegExp
16+
activeMatch?: RegExp | string
1717

1818
/**
1919
* The `aria-label` attribute

docs/reference/node-api.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ const homeSourceFile = app.dir.source('README.md')
213213
- Signature:
214214

215215
```ts
216-
writeTemp(file: string, content: string): Promise<string>
216+
declare const writeTemp = (file: string, content: string) => Promise<string>
217217
```
218218

219219
- Parameters:
@@ -250,7 +250,7 @@ import { foo } from '@temp/foo'
250250
- Signature:
251251

252252
```ts
253-
init(): Promise<void>
253+
declare const init = () => Promise<void>
254254
```
255255

256256
- Details:
@@ -265,7 +265,7 @@ init(): Promise<void>
265265
- Signature:
266266

267267
```ts
268-
prepare(): Promise<void>
268+
declare const prepare = () => Promise<void>
269269
```
270270

271271
- Details:
@@ -280,7 +280,7 @@ prepare(): Promise<void>
280280
- Signature:
281281

282282
```ts
283-
build(): Promise<void>
283+
declare const build = () => Promise<void>
284284
```
285285

286286
- Details:
@@ -298,7 +298,7 @@ build(): Promise<void>
298298
- Signature:
299299

300300
```ts
301-
dev(): Promise<() => Promise<void>>
301+
declare const dev = () => Promise<() => Promise<void>>
302302
```
303303

304304
- Details:

docs/zh/advanced/cookbook/making-a-theme-extendable.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ import { getDirname, path } from 'vuepress/utils'
3434

3535
const __dirname = getDirname(import.meta.url)
3636

37-
export const fooTheme = (options): Theme => {
38-
return {
39-
name: 'vuepress-theme-foo',
40-
alias: {
41-
// 为可替换的组件设置别名
42-
'@theme/Navbar.vue': path.resolve(__dirname, 'components/Navbar.vue'),
43-
'@theme/Sidebar.vue': path.resolve(__dirname, 'components/Sidebar.vue'),
44-
},
45-
}
46-
}
37+
export const fooTheme = (options): Theme => ({
38+
name: 'vuepress-theme-foo',
39+
alias: {
40+
// 为可替换的组件设置别名
41+
'@theme/Navbar.vue': path.resolve(__dirname, 'components/Navbar.vue'),
42+
'@theme/Sidebar.vue': path.resolve(__dirname, 'components/Sidebar.vue'),
43+
},
44+
})
4745
```
4846

4947
然后,在你的主题中通过别名来使用这些组件:

docs/zh/advanced/cookbook/usage-of-client-config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ export default defineClientConfig({
130130
使用不支持 SSR 的功能的另一种方式就是将他们放在 [onMounted](https://staging-cn.vuejs.org/api/composition-api-lifecycle.html#onmounted) Hook 中:
131131

132132
```ts
133-
import { defineClientConfig } from 'vuepress/client'
134133
import { onMounted } from 'vue'
134+
import { defineClientConfig } from 'vuepress/client'
135135

136136
export default defineClientConfig({
137137
setup() {

docs/zh/advanced/plugin.md

+12-20
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,24 @@ const fooPlugin = {
1818
插件还可以是一个接收 [App 实例](../reference/node-api.md#app) 作为参数,且返回值为 _插件对象_ 的函数,称之为 _插件函数_
1919

2020
```ts
21-
const barPlugin = (app) => {
22-
return {
23-
name: 'vuepress-plugin-bar',
24-
// ...
25-
}
26-
}
21+
const barPlugin = (app) => ({
22+
name: 'vuepress-plugin-bar',
23+
// ...
24+
})
2725
```
2826

2927
插件通常需要允许用户传入配置,因此我们一般都会提供给用户一个函数来接收配置,然后将 _插件对象_ 或者 _插件函数_ 作为返回值。于是,你的插件应该转换成这样的形式:
3028

3129
```ts
32-
const fooPlugin = (options) => {
33-
return {
34-
name: 'vuepress-plugin-foo',
35-
// ...
36-
}
37-
}
30+
const fooPlugin = (options) => ({
31+
name: 'vuepress-plugin-foo',
32+
// ...
33+
})
3834

39-
const barPlugin = (options) => {
40-
return (app) => {
41-
return {
42-
name: 'vuepress-plugin-bar',
43-
// ...
44-
}
45-
}
46-
}
35+
const barPlugin = (options) => (app) => ({
36+
name: 'vuepress-plugin-bar',
37+
// ...
38+
})
4739
```
4840

4941
## 发布到 NPM

0 commit comments

Comments
 (0)