Skip to content

Commit 78faf34

Browse files
committed
chore: use ESLint V9 and fix errors
1 parent 8868be3 commit 78faf34

File tree

19 files changed

+4898
-1242
lines changed

19 files changed

+4898
-1242
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pnpm-debug.log*
1818

1919
# Editor directories and files
2020
.idea
21-
.vscode
2221
*.suo
2322
*.ntvs*
2423
*.njsproj

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
shamefully-hoist=true
2+
auto-install-peers=true

.vitepress/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { resolve } from 'path'
2-
import { defineConfig } from 'vitepress'
32
import banner from 'vite-plugin-banner'
3+
import { defineConfig } from 'vitepress'
4+
import pkg from '../package.json'
45
import { head } from './head'
56
import { nav } from './nav'
67
import { sidebar } from './sidebar'
7-
import pkg from '../package.json'
88

99
export default defineConfig({
1010
appearance: 'dark',

.vitepress/theme/components/GitalkComment.vue

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ onMounted(init)
3838
color: var(--c-brand) !important;
3939
}
4040
.gitalk-container :deep(.gt-container) .gt-header-textarea {
41-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
42-
Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
41+
font-family:
42+
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
43+
Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
4344
background-color: var(--c-bg-light);
4445
}
45-
.gitalk-container
46-
:deep(.gt-container)
47-
.gt-svg
48-
svg {
46+
.gitalk-container :deep(.gt-container) .gt-svg svg {
4947
fill: var(--c-brand);
5048
}
5149
.gitalk-container :deep(.gt-container) .gt-link {
@@ -59,28 +57,17 @@ onMounted(init)
5957
color: var(--c-brand);
6058
background-color: var(--c-bg);
6159
}
62-
.gitalk-container
63-
:deep(.gt-container)
64-
.gt-comments
65-
.gt-comments-null {
60+
.gitalk-container :deep(.gt-container) .gt-comments .gt-comments-null {
6661
color: var(--c-text);
6762
}
68-
.gitalk-container
69-
:deep(.gt-container)
70-
.gt-comment-content {
63+
.gitalk-container :deep(.gt-container) .gt-comment-content {
7164
background-color: var(--c-bg-light);
7265
box-shadow: none;
7366
}
74-
.gitalk-container
75-
:deep(.gt-container)
76-
.gt-comment-content
77-
.gt-comment-body {
67+
.gitalk-container :deep(.gt-container) .gt-comment-content .gt-comment-body {
7868
color: var(--c-text) !important;
7969
}
80-
.gitalk-container
81-
:deep(.gt-container)
82-
.gt-comment-content
83-
blockquote {
70+
.gitalk-container :deep(.gt-container) .gt-comment-content blockquote {
8471
color: var(--c-text-quote) !important;
8572
border: 0;
8673
background-color: var(--c-bg-lighter);

.vitepress/theme/components/ImgWrap.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const isDark = ref<boolean>(false)
3131
3232
// 动态切换的图片地址
3333
const imgUrl = computed(() =>
34-
isDark.value && props.dark ? props.dark : props.src
34+
isDark.value && props.dark ? props.dark : props.src,
3535
)
3636
3737
// 侦听器

.vitepress/theme/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { inBrowser } from 'vitepress'
2-
import defaultTheme from 'vitepress/theme'
31
import { createVitePressBaiduAnalytics } from '@web-analytics/vue'
2+
import { type Theme, inBrowser } from 'vitepress'
3+
import defaultTheme from 'vitepress/theme'
44
import GitalkComment from './components/GitalkComment.vue'
55
import ImgWrap from './components/ImgWrap.vue'
66
import ReadingTips from './components/ReadingTips.md'
7-
import { setSymbolStyle, replaceSymbol } from './plugins/symbol'
87
import { isInvalidRoute, redirect } from './plugins/redirect'
8+
import { replaceSymbol, setSymbolStyle } from './plugins/symbol'
99
import './styles/custom.css'
10-
import type { Theme } from 'vitepress'
1110

1211
const { baiduAnalytics, registerBaiduAnalytics } =
1312
createVitePressBaiduAnalytics()

.vitepress/theme/plugins/redirect.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
11
import { inBrowser } from 'vitepress'
22

3-
/**
4-
* 重定向的 Map 表
5-
*/
3+
/** 重定向的 Map 表 */
64
export const redirectMap = {
75
update: 'upgrade',
86
}
97

10-
/**
11-
* 根据页面 URL 提取路由名称
12-
*/
8+
/** 根据页面 URL 提取路由名称 */
139
export function getRouteName() {
1410
if (!inBrowser) return ''
1511
const { pathname } = window.location
1612
const routeName = pathname.slice(1).replace('.html', '')
1713
return routeName
1814
}
1915

20-
/**
21-
* 判断是否无效路由
22-
*/
16+
/** 判断是否无效路由 */
2317
export function isInvalidRoute() {
2418
if (!inBrowser) return false
2519
const routeName = getRouteName()
2620
const keys = Object.keys(redirectMap)
2721
return keys.includes(routeName)
2822
}
2923

30-
/**
31-
* 获取重定向目标
32-
*/
24+
/** 获取重定向目标 */
3325
export function redirectTarget() {
3426
if (!inBrowser) return '/'
35-
const routeName = getRouteName()
36-
return `/${redirectMap[routeName]}.html` || '/'
27+
const routeName = getRouteName() as keyof typeof redirectMap
28+
const target = redirectMap[routeName]
29+
return target ? `/${target}.html` : '/'
3730
}
3831

39-
/**
40-
* 重定向
41-
*/
32+
/** 重定向 */
4233
export function redirect() {
4334
if (!inBrowser) return
4435
window.location.replace(redirectTarget())

.vitepress/theme/plugins/symbol.ts

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { inBrowser } from 'vitepress'
21
import { loadRes } from '@bassist/utils'
2+
import { inBrowser } from 'vitepress'
33

44
interface Config {
55
hot: string
@@ -18,9 +18,7 @@ const iconConfig: Config = {
1818
new: '<i class="sidebar__icon--default sidebar__icon--new"></i>',
1919
}
2020

21-
/**
22-
* 设置图标样式
23-
*/
21+
/** 设置图标样式 */
2422
export function setSymbolStyle() {
2523
if (!inBrowser) return
2624
try {
@@ -69,16 +67,14 @@ export function setSymbolStyle() {
6967
id: 'symbol-plugin',
7068
resource: CSS,
7169
}).catch((e) => {
72-
console.log(e)
70+
console.error(e)
7371
})
7472
} catch (e) {
75-
console.log(e)
73+
console.error(e)
7674
}
7775
}
7876

79-
/**
80-
* 执行标记替换
81-
*/
77+
/** 执行标记替换 */
8278
export function replaceSymbol() {
8379
if (!inBrowser) return
8480
setTimeout(() => {
@@ -95,35 +91,31 @@ export function replaceSymbol() {
9591
doms.forEach((item) => {
9692
let html = item.innerHTML
9793

98-
for (const key in markConfig) {
99-
if (Object.hasOwnProperty.call(markConfig, key)) {
100-
const k = key as keyof Config
101-
const mark = markConfig[k]
102-
const icon = iconConfig[k]
103-
const reg = new RegExp(mark, 'img')
94+
for (const [key, mark] of Object.entries(markConfig)) {
95+
const k = key as keyof Config
96+
const icon = iconConfig[k]
97+
const reg = new RegExp(mark, 'img')
10498

105-
// 只处理包含标记的元素
106-
if (html.includes(mark)) {
107-
// 部分元素不显示图标
108-
const { nodeName } = item
109-
switch (nodeName) {
110-
case 'H2':
111-
case 'H3':
112-
case 'H4':
113-
html = html.replace(reg, '')
114-
break
115-
default:
116-
html = html.replace(reg, icon)
117-
}
118-
119-
// 渲染
120-
item.innerHTML = html
99+
// 只处理包含标记的元素
100+
if (html.includes(mark)) {
101+
const { nodeName } = item
102+
switch (nodeName) {
103+
case 'H2':
104+
case 'H3':
105+
case 'H4':
106+
html = html.replace(reg, '')
107+
break
108+
default:
109+
html = html.replace(reg, icon)
121110
}
111+
112+
// 渲染
113+
item.innerHTML = html
122114
}
123115
}
124116
})
125117
} catch (e) {
126-
console.log(e)
118+
console.error(e)
127119
}
128120
}, 100)
129121
}

.vitepress/vite-env.d.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
/// <reference types="vite/client" />
22

33
declare module '*.vue' {
4-
import { DefineComponent } from 'vue'
5-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
6-
const component: DefineComponent<{}, {}, any>
4+
import { type DefineComponent } from 'vue'
5+
6+
const component: DefineComponent<object, object, any>
7+
export default component
8+
}
9+
10+
declare module '*.md' {
11+
// eslint-disable-next-line no-duplicate-imports
12+
import { type DefineComponent } from 'vue'
13+
14+
const component: DefineComponent<object, object, any>
715
export default component
816
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"cSpell.words": ["Undici"],
3+
"editor.formatOnSave": true,
4+
"eslint.useFlatConfig": true,
5+
"editor.codeActionsOnSave": {
6+
"source.fixAll.eslint": "always",
7+
"source.fixAll.prettier": "always"
8+
}
9+
}

0 commit comments

Comments
 (0)