Skip to content

Commit f85c1c6

Browse files
committed
refactor: fix lint and build errors
1 parent ec6ed78 commit f85c1c6

File tree

10 files changed

+36
-32
lines changed

10 files changed

+36
-32
lines changed

src/auth/auth-manager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ authProvider.onDidChangeSessions(async e => {
2727
await BlogExportProvider.optionalInstance?.refreshRecords({ force: false, clearCache: true })
2828
})
2929

30+
// eslint-disable-next-line @typescript-eslint/no-namespace
3031
export namespace AuthManager {
3132
export async function isAuthed() {
3233
const sessionJsonList = await LocalState.getSecret(ExtConst.EXT_SESSION_STORAGE_KEY)
@@ -38,7 +39,7 @@ export namespace AuthManager {
3839
try {
3940
return authentication.getSession(authProvider.providerId, [], opt)
4041
} catch (e) {
41-
throw Error(`创建/获取 Session 失败: ${<string>e}`)
42+
throw Error(`创建/获取 Session 失败: ${e as string}`)
4243
}
4344
}
4445

@@ -68,7 +69,7 @@ export namespace AuthManager {
6869
await authProvider.removeSession(session.id)
6970
await Oauth.revokeToken(token)
7071
} catch (e) {
71-
void Alert.err(`登出发生错误: ${<string>e}`)
72+
void Alert.err(`登出发生错误: ${e as string}`)
7273
throw e
7374
}
7475
}

src/auth/auth-provider.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthenticationSession as AuthSession, AuthenticationSession } from 'vscode'
1+
import { AuthenticationSession as AuthSession, AuthenticationProviderSessionOptions, AuthenticationSession } from 'vscode'
22
import { genVerifyChallengePair } from '@/service/code-challenge'
33
import {
44
authentication,
@@ -22,7 +22,7 @@ import { LocalState } from '@/ctx/local-state'
2222
import { ExtConst } from '@/ctx/ext-const'
2323
import { UserService } from '@/service/user.service'
2424

25-
async function browserSignIn(challengeCode: string, scopes: string[]) {
25+
async function browserSignIn(challengeCode: string, scopes: readonly string[]) {
2626
const para = consUrlPara(
2727
['client_id', ExtConst.CLIENT_ID],
2828
['client_secret', ExtConst.CLIENT_SEC],
@@ -39,7 +39,7 @@ async function browserSignIn(challengeCode: string, scopes: string[]) {
3939
try {
4040
await env.openExternal(uri)
4141
} catch (e) {
42-
void Alert.err(`重定向失败: ${<string>e}`)
42+
void Alert.err(`重定向失败: ${e as string}`)
4343
}
4444
}
4545

@@ -73,18 +73,18 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
7373
this._usePat = true
7474
}
7575

76-
async getSessions(scopes?: string[]): Promise<readonly AuthSession[]> {
76+
async getSessions(scopes: readonly string[] | undefined, options: AuthenticationProviderSessionOptions):
77+
Promise<AuthenticationSession[]> {
7778
const sessions = await this.getAllSessions()
7879
const parsedScopes = this.ensureScopes(scopes)
79-
8080
return sessions.filter(({ scopes: sessionScopes }) => parsedScopes.every(x => sessionScopes.includes(x)))
8181
}
8282

8383
createSession(scopes: string[]) {
8484
return this._usePat ? this.createSessionFromPat(scopes) : this.createSessionFromBrowser(scopes)
8585
}
8686

87-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
87+
8888
async createSessionFromPat(scopes: string[]) {
8989
const validateInput = (value: string) => {
9090
if (value.trim().length === 0)
@@ -181,7 +181,7 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
181181
else keep.push(s)
182182
return { remove, keep }
183183
},
184-
{ remove: <AuthSession[]>[], keep: <AuthSession[]>[] }
184+
{ remove: [] as AuthSession[], keep: [] as AuthSession[] }
185185
)
186186
await LocalState.setSecret(ExtConst.EXT_SESSION_STORAGE_KEY, JSON.stringify(data.keep))
187187
this._sessionChangeEmitter.fire({ removed: data.remove, added: undefined, changed: undefined })
@@ -204,15 +204,15 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
204204

205205
const { accountId, displayName } = userInfo
206206

207-
const session = <AuthenticationSession>{
207+
const session = {
208208
account: {
209209
id: new Number(accountId).toString(),
210210
label: displayName,
211211
},
212212
id: `${this.providerId}-${userInfo.accountId}`,
213213
accessToken: token,
214-
scopes: this.ensureScopes(null),
215-
}
214+
scopes: this.ensureScopes(undefined),
215+
} as AuthenticationSession
216216

217217
await LocalState.setSecret(ExtConst.EXT_SESSION_STORAGE_KEY, JSON.stringify([session]))
218218

@@ -239,9 +239,9 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
239239
}
240240

241241
private ensureScopes(
242-
scopes: string[] | null | undefined,
242+
scopes: readonly string[] | undefined,
243243
{ default: defaultScopes = ExtConst.OAUTH_SCOPES } = {}
244-
): string[] {
244+
): readonly string[] {
245245
return scopes == null || scopes.length <= 0 ? defaultScopes : scopes
246246
}
247247
}

src/auth/oauth.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ function getAuthedOauthReq() {
77
return new OauthReq(ExtConst.CLIENT_ID, ExtConst.CLIENT_SEC)
88
}
99

10+
// eslint-disable-next-line @typescript-eslint/no-namespace
1011
export namespace Oauth {
1112
export function getToken(verifyCode: string, authCode: string) {
1213
const req = getAuthedOauthReq()
1314
try {
1415
return req.getToken(authCode, verifyCode, globalCtx.extUrl)
1516
} catch (e) {
16-
void Alert.err(`获取 Token 失败: ${<string>e}`)
17+
void Alert.err(`获取 Token 失败: ${e as string}`)
1718
throw e
1819
}
1920
}
@@ -23,7 +24,7 @@ export namespace Oauth {
2324
const req = getAuthedOauthReq()
2425
return req.revokeToken(token)
2526
} catch (e) {
26-
void Alert.err(`撤销 Token 失败: ${<string>e}`)
27+
void Alert.err(`撤销 Token 失败: ${e as string}`)
2728
}
2829
}
2930
}

src/cmd/blog-export/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function createBlogExport() {
1717
await BlogExportApi.create()
1818
await BlogExportProvider.optionalInstance?.refreshRecords()
1919
} catch (e) {
20-
void Alert.err(`创建备份失败: ${<string>e}`)
20+
void Alert.err(`创建备份失败: ${e as string}`)
2121
return false
2222
}
2323
}

src/cmd/blog-export/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function deleteExportRecordItem(item: BlogExportRecordTreeItem) {
4848
const hasDeleted = await BlogExportApi.del(record.id)
4949
.then(() => true)
5050
.catch(e => {
51-
void Alert.err(`删除博客备份失败: ${<string>e}`)
51+
void Alert.err(`删除博客备份失败: ${e as string}`)
5252
return false
5353
})
5454
if (hasDeleted) if (downloaded !== undefined) await removeDownloadedBlogExport(downloaded, { shouldDeleteLocal })

src/cmd/pdf/export-pdf.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type puppeteer from 'puppeteer-core'
21
import fs from 'fs'
32
import path from 'path'
43
import os from 'os'
@@ -14,6 +13,7 @@ import { PostEditDto } from '@/model/post-edit-dto'
1413
import { PostPdfTemplateBuilder } from '@/cmd/pdf/post-pdf-template-builder'
1514
import { ChromiumCfg } from '@/ctx/cfg/chromium'
1615
import { UserService } from '@/service/user.service'
16+
import { Page } from 'puppeteer-core'
1717

1818
async function launchBrowser(chromiumPath: string) {
1919
try {
@@ -37,7 +37,7 @@ const exportOne = async (
3737
idx: number,
3838
total: number,
3939
post: Post,
40-
page: puppeteer.Page,
40+
page: Page,
4141
targetFileUri: Uri,
4242
progress: Progress<{ message: string; increment: number }>,
4343
blogApp: string
@@ -70,7 +70,7 @@ const exportOne = async (
7070
report(-100)
7171
}
7272

73-
const createPdfBuffer = (page: puppeteer.Page) =>
73+
const createPdfBuffer = (page: Page) =>
7474
page.pdf({
7575
format: 'a4',
7676
printBackground: true,
@@ -82,7 +82,7 @@ const createPdfBuffer = (page: puppeteer.Page) =>
8282
},
8383
})
8484

85-
const writePdfToFile = (dir: Uri, post: Post, buffer: Buffer) =>
85+
const writePdfToFile = (dir: Uri, post: Post, buffer: Uint8Array<ArrayBufferLike>) =>
8686
new Promise<void>(resolve => {
8787
fs.writeFile(path.join(dir.fsPath, `${post.title}.pdf`), buffer, () => {
8888
resolve()
@@ -202,7 +202,7 @@ export async function exportPostToPdf(input?: Post | PostTreeItem | Uri): Promis
202202
try {
203203
await exportOne(idx++, total, post, page, dir, progress, blogApp)
204204
} catch (e) {
205-
void Alert.err(`导出 ${post.title} 失败: ${<string>e}`)
205+
void Alert.err(`导出 ${post.title} 失败: ${e as string}`)
206206
}
207207
}
208208
await page.close()

src/cmd/pdf/post-pdf-template-builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { markdownItFactory } from '@cnblogs/markdown-it-presets'
77
import { UserService } from '@/service/user.service'
88
import { PostCateStore } from '@/stores/post-cate-store'
99

10+
// eslint-disable-next-line @typescript-eslint/no-namespace
1011
export namespace PostPdfTemplateBuilder {
1112
export const HighlightedMessage = 'markdown-highlight-finished'
1213

src/cmd/post-cat/del-selected-cat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function delSelectedCat(input?: PostCatTreeItem | PostCat) {
5151
await PostCatService.del(category.categoryId)
5252
idx++
5353
} catch (e) {
54-
void Alert.err(`删除失败: ${<string>e}`)
54+
void Alert.err(`删除失败: ${e as string}`)
5555
}
5656
}
5757

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function activate(ctx: ExtensionContext) {
2424
setupCmd()
2525
setupExtTreeView()
2626
} catch (e) {
27-
void Alert.err(`扩展激活失败,[立即反馈](https://github.com/cnblogs/vscode-cnb/issues),错误信息:${<string>e}`)
27+
void Alert.err(`扩展激活失败,[立即反馈](https://github.com/cnblogs/vscode-cnb/issues),错误信息:${e as string}`)
2828
throw e
2929
}
3030

src/service/post/post-cat.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ async function getAuthedPostCatReq() {
1515
return new PostCatReq(new Token(token, isPatToken))
1616
}
1717

18+
// eslint-disable-next-line @typescript-eslint/no-namespace
1819
export namespace PostCatService {
1920
export async function getAll() {
2021
const req = await getAuthedPostCatReq()
2122
try {
2223
const resp = await req.getAll()
23-
const { categories } = <{ categories: PostCat[] }>JSON.parse(resp)
24+
const { categories } = JSON.parse(resp) as { categories: PostCat[] }
2425
if (categories == null) return []
2526
return categories
2627
} catch (e) {
27-
if (await UserService.hasBlog()) void Alert.err(`查询随笔分类失败: ${<string>e}`)
28+
if (await UserService.hasBlog()) void Alert.err(`查询随笔分类失败: ${e as string}`)
2829
throw e
2930
}
3031
}
@@ -35,7 +36,7 @@ export namespace PostCatService {
3536
try {
3637
await req.create(body)
3738
} catch (e) {
38-
void Alert.err(`创建分类失败: ${<string>e}`)
39+
void Alert.err(`创建分类失败: ${e as string}`)
3940
}
4041
}
4142

@@ -45,7 +46,7 @@ export namespace PostCatService {
4546
try {
4647
await req.update(category.categoryId, body)
4748
} catch (e) {
48-
void Alert.err(`更新分类失败: ${<string>e}`)
49+
void Alert.err(`更新分类失败: ${e as string}`)
4950
}
5051
}
5152

@@ -54,7 +55,7 @@ export namespace PostCatService {
5455
try {
5556
await req.del(categoryId)
5657
} catch (e) {
57-
void Alert.err(`删除分类失败: ${<string>e}`)
58+
void Alert.err(`删除分类失败: ${e as string}`)
5859
}
5960
}
6061

@@ -64,9 +65,9 @@ export namespace PostCatService {
6465

6566
try {
6667
const resp = await req.getSitePresetList()
67-
siteCategoryCache = <SiteCat[]>JSON.parse(resp)
68+
siteCategoryCache = JSON.parse(resp) as SiteCat[]
6869
} catch (e) {
69-
void Alert.err(`获取随笔分类失败: ${<string>e}`)
70+
void Alert.err(`获取随笔分类失败: ${e as string}`)
7071
}
7172

7273
return siteCategoryCache

0 commit comments

Comments
 (0)