style: 完成所有文件的lint

This commit is contained in:
claude-code-best
2026-05-01 21:39:30 +08:00
parent d136872cc9
commit 6182015005
1333 changed files with 68255 additions and 77882 deletions

View File

@@ -21,9 +21,9 @@ describe('AES-128-ECB', () => {
test('different keys produce different ciphertext', () => {
const plaintext = Buffer.from('test data')
expect(
expect(encryptAesEcb(plaintext, randomBytes(16))).not.toEqual(
encryptAesEcb(plaintext, randomBytes(16)),
).not.toEqual(encryptAesEcb(plaintext, randomBytes(16)))
)
})
})
@@ -63,9 +63,7 @@ describe('CDN URL builders', () => {
})
test('buildCdnUploadUrl encodes params', () => {
expect(
buildCdnUploadUrl('https://cdn.example.com', 'param1', 'key1'),
).toBe(
expect(buildCdnUploadUrl('https://cdn.example.com', 'param1', 'key1')).toBe(
'https://cdn.example.com/upload?encrypted_query_param=param1&filekey=key1',
)
})

View File

@@ -15,8 +15,9 @@ describe('markdownToPlainText', () => {
})
test('removes code block fences', () => {
expect(markdownToPlainText("```js\nconsole.log('hi');\n```"))
.toBe("console.log('hi');")
expect(markdownToPlainText("```js\nconsole.log('hi');\n```")).toBe(
"console.log('hi');",
)
})
test('converts links to text with URL', () => {
@@ -26,7 +27,8 @@ describe('markdownToPlainText', () => {
})
test('handles mixed markdown', () => {
expect(markdownToPlainText('# Hello\n\n**bold** and *italic* with `code`'))
.toBe('Hello\n\nbold and italic with code')
expect(
markdownToPlainText('# Hello\n\n**bold** and *italic* with `code`'),
).toBe('Hello\n\nbold and italic with code')
})
})

View File

@@ -1,4 +1,9 @@
import { clearAccount, DEFAULT_BASE_URL, loadAccount, saveAccount } from './accounts.js'
import {
clearAccount,
DEFAULT_BASE_URL,
loadAccount,
saveAccount,
} from './accounts.js'
import { startLogin, waitForLogin } from './login.js'
import { confirmPairing } from './pairing.js'
import { runWeixinMcpServer } from './server.js'
@@ -102,7 +107,9 @@ export async function handleWeixinCli(
switch (subcommand) {
case 'serve':
if (!serverDeps) {
process.stderr.write('[weixin] serve handler not available in this context.\n')
process.stderr.write(
'[weixin] serve handler not available in this context.\n',
)
process.exit(1)
}
await runWeixinMcpServer(version ?? '0.0.0', serverDeps)

View File

@@ -25,7 +25,9 @@ async function renderQrCodeToTerminal(qrcodeUrl: string): Promise<void> {
}
export async function startLogin(apiBaseUrl: string): Promise<QRCodeResult> {
const response = await fetch(`${apiBaseUrl}/ilink/bot/get_bot_qrcode?bot_type=3`)
const response = await fetch(
`${apiBaseUrl}/ilink/bot/get_bot_qrcode?bot_type=3`,
)
if (!response.ok) {
throw new Error(`Failed to get QR code: HTTP ${response.status}`)
}
@@ -99,9 +101,7 @@ export async function waitForLogin(params: {
message: 'Connected to WeChat successfully!',
}
case 'scaned':
process.stderr.write(
'QR code scanned, waiting for confirmation...\n',
)
process.stderr.write('QR code scanned, waiting for confirmation...\n')
break
case 'expired': {
retryCount += 1

View File

@@ -4,12 +4,7 @@ import {
createHash,
randomBytes,
} from 'node:crypto'
import {
existsSync,
mkdirSync,
readFileSync,
writeFileSync,
} from 'node:fs'
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { basename, extname, join } from 'node:path'
import { getUploadUrl } from './api.js'
@@ -49,7 +44,10 @@ export function parseAesKey(aesKeyBase64: string): Buffer {
if (decoded.length === 16) {
return decoded
}
if (decoded.length === 32 && /^[0-9a-fA-F]{32}$/.test(decoded.toString('ascii'))) {
if (
decoded.length === 32 &&
/^[0-9a-fA-F]{32}$/.test(decoded.toString('ascii'))
) {
return Buffer.from(decoded.toString('ascii'), 'hex')
}
throw new Error(

View File

@@ -1,9 +1,4 @@
import {
existsSync,
mkdirSync,
readFileSync,
writeFileSync,
} from 'node:fs'
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { basename, join } from 'node:path'
// Matches the canonical definition in src/services/mcp/channelPermissions.ts
@@ -12,9 +7,17 @@ import { getUpdates } from './api.js'
import { getStateDir } from './accounts.js'
import { downloadAndDecrypt } from './media.js'
import { addPendingPairing, isAllowed } from './pairing.js'
import { consumePendingPermission, setActivePermissionChat } from './permissions.js'
import {
consumePendingPermission,
setActivePermissionChat,
} from './permissions.js'
import { sendText } from './send.js'
import { MessageItemType, MessageType, type MessageItem, type WeixinMessage } from './types.js'
import {
MessageItemType,
MessageType,
type MessageItem,
type WeixinMessage,
} from './types.js'
const contextTokens = new Map<string, string>()
@@ -124,8 +127,7 @@ export function extractPermissionReply(
): { requestId: string; behavior: 'allow' | 'deny' } | null {
const match = text.match(PERMISSION_REPLY_RE)
if (!match) return null
const behavior =
match[1]?.toLowerCase().startsWith('y') ? 'allow' : 'deny'
const behavior = match[1]?.toLowerCase().startsWith('y') ? 'allow' : 'deny'
const requestId = match[2]?.toLowerCase()
if (!requestId) return null
return { requestId, behavior }

View File

@@ -24,7 +24,10 @@ function loadPending(): Record<string, PendingEntry> {
const path = pendingPath()
if (!existsSync(path)) return {}
try {
return JSON.parse(readFileSync(path, 'utf-8')) as Record<string, PendingEntry>
return JSON.parse(readFileSync(path, 'utf-8')) as Record<
string,
PendingEntry
>
} catch {
return {}
}

View File

@@ -125,7 +125,9 @@ export function createWeixinMcpServer(version: string): Server {
const chatId = typeof args?.chat_id === 'string' ? args.chat_id : ''
const text = typeof args?.text === 'string' ? args.text : ''
const files = Array.isArray(args?.files)
? args.files.filter((value): value is string => typeof value === 'string')
? args.files.filter(
(value): value is string => typeof value === 'string',
)
: undefined
if (!chatId || !text) {
@@ -162,7 +164,9 @@ export function createWeixinMcpServer(version: string): Server {
}
return {
content: [{ type: 'text', text: 'Message sent with attachments.' }],
content: [
{ type: 'text', text: 'Message sent with attachments.' },
],
}
}
@@ -211,7 +215,9 @@ export function createWeixinMcpServer(version: string): Server {
}
} catch (error) {
return {
content: [{ type: 'text', text: `Failed to send typing: ${error}` }],
content: [
{ type: 'text', text: `Failed to send typing: ${error}` },
],
isError: true,
}
}
@@ -264,11 +270,7 @@ export async function runWeixinMcpServer(
}
try {
savePendingPermission(
request,
targetChat.chatId,
targetChat.contextToken,
)
savePendingPermission(request, targetChat.chatId, targetChat.contextToken)
await sendText({
to: targetChat.chatId,
text: formatPermissionRequestMessage(request),