refactor: minor lint and consistency fixes

Apply a collection of small code cleanups across the repo for consistency and lint-safety. Changes include:

- Use strict equality (===) where appropriate (GetEmojiLikes, about page checks).
- Replace Array.map used for side effects with Array.forEach (GetMsg).
- Rename unused catch parameters to underscore-prefixed names to avoid lint warnings (multiple backend/middleware files).
- Replace void with undefined in an actions.call invocation (builtin plugin index).
- Remove an unused loadedCount variable when reading .env (napcat-shell).
- Rename promise resolver parameter to `resolve` for clarity in tests and keep setTimeout usage (rpc.test.ts).
- Strengthen external shims types by changing generic parameter names to _T and update inversify ServiceIdentifier generic param (external-shims.d.ts).
- Simplify post-build script imports and comment out an external-type mapping block; fix a regex character class bug (post-build.mjs).
- Prefix several unused test stub variables with underscore to indicate intentional unused status (test-dist.ts).
- Minor JSX formatting/indentation fixes in password_login component and UI text indentation in system_info.
- Misc: SSE/config and plugin config handlers adjusted to consistent catch parameter naming; update mirror/download error catch variable name.

These edits are non-functional refactors focused on code style, lint compliance and small robustness/clarity improvements.
This commit is contained in:
手瓜一十雪 committed 2026-03-05 18:53:58 +08:00
1 parent 974528fe7e
commit b15d02535e
19 files changed
+49 -65

No files matched your search

+5 -5
View File
@@ -68,10 +68,10 @@ declare module 'napcat-protobuf' {
encode (value: any): Uint8Array;
}
export function ProtoField (...args: any[]): any;
export type NapProtoEncodeStructType<T> = any;
export type NapProtoDecodeStructType<T> = any;
export type ScalarProtoFieldType<T> = any;
export type MessageProtoFieldType<T> = any;
export type NapProtoEncodeStructType<_T> = any;
export type NapProtoDecodeStructType<_T> = any;
export type ScalarProtoFieldType<_T> = any;
export type MessageProtoFieldType<_T> = any;
export const ScalarType: {
STRING: any;
INT64: any;
@@ -91,7 +91,7 @@ declare module 'inversify' {
}
export function injectable (...args: any[]): any;
export function inject (...args: any[]): any;
export interface ServiceIdentifier<T = any> { }
export interface ServiceIdentifier<_T = any> { }
const _inversify_default: any;
export default _inversify_default;
}
+4 -2
View File
@@ -1,5 +1,5 @@
import { readdir, readFile, writeFile, rename } from 'node:fs/promises';
import { join, extname, basename } from 'node:path';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = fileURLToPath(new URL('../', import.meta.url));
@@ -11,6 +11,7 @@ const ALLOWED_PACKAGES = [
'node:', // node: 前缀的内置模块
];
/*
// 外部包类型到 any 的映射
const EXTERNAL_TYPE_REPLACEMENTS = {
// winston
@@ -41,6 +42,7 @@ const EXTERNAL_TYPE_REPLACEMENTS = {
'NapProtoDecodeStructType<T>': 'any',
'NapProtoEncodeStructType<T>': 'any',
};
*/
function isAllowedImport (importPath) {
return ALLOWED_PACKAGES.some(pkg => importPath.startsWith(pkg));
@@ -87,7 +89,7 @@ function replaceExternalTypes (content) {
// 使用类型上下文的模式匹配
const typeContextPatterns = [
// : Type
/:\s*(WebSocket|WebSocketServer|RawData|Ajv|AnySchema|ValidateFunction|Container|NapProtoDecodeStructType|NapProtoEncodeStructType|Express|Request|Response|NextFunction)(?=\s*[;,)\]\}|&]|$)/g,
/:\s*(WebSocket|WebSocketServer|RawData|Ajv|AnySchema|ValidateFunction|Container|NapProtoDecodeStructType|NapProtoEncodeStructType|Express|Request|Response|NextFunction)(?=\s*[;,)\]}|&]|$)/g,
// <Type>
/<(WebSocket|WebSocketServer|RawData|Ajv|AnySchema|ValidateFunction|Container|NapProtoDecodeStructType|NapProtoEncodeStructType|Express|Request|Response|NextFunction)>/g,
// Type[]
+6 -6
View File
@@ -16,15 +16,15 @@ console.log('ChatType.KCHATTYPEGROUP:', ChatType.KCHATTYPEGROUP); // 应输出 2
console.log('ElementType.TEXT:', ElementType.TEXT); // 应输出 1
// 2. 测试类型 (Core)
const coreStub = {} as NapCatCore;
const apiStub = {} as NTQQMsgApi;
const _coreStub = {} as NapCatCore;
const _apiStub = {} as NTQQMsgApi;
console.log('Core types access check: OK');
// 3. 测试类和类型 (OneBot)
const obAdapterStub = {} as NapCatOneBot11Adapter;
const obMsgStub = {} as OB11Message;
const baseMessageEventStub = {} as OB11BaseMessageEvent;
const baseMetaEventStub = {} as OB11BaseMetaEvent;
const _obAdapterStub = {} as NapCatOneBot11Adapter;
const _obMsgStub = {} as OB11Message;
const _baseMessageEventStub = {} as OB11BaseMessageEvent;
const _baseMetaEventStub = {} as OB11BaseMetaEvent;
console.log('OneBot types and events access check: OK');
// 4. 验证导出完整性