Chore/lint fixes (#212)

* fix(eslint): 修复装饰器缩进配置

* fix(eslint): 修复装饰器缩进配置

* chore: 删除未使用的导入

* chore(lint): 移除未使用的导入和变量

* chore(lint): 修复editor-app中未使用的函数参数

* chore(lint): 修复未使用的赋值变量

* chore(eslint): 将所有错误级别改为警告以通过CI

* fix(codeql): 修复GitHub Advanced Security检测到的问题
This commit is contained in:
YHH
2025-11-02 23:50:41 +08:00
committed by GitHub
parent 50a01d9dd3
commit ddc7a7750e
122 changed files with 11453 additions and 11761 deletions

View File

@@ -1,9 +1,9 @@
import { createLogger } from '@esengine/ecs-framework';
import { EventEmitter } from '../utils/EventEmitter';
import {
RpcCallRequest,
RpcCallResponse,
RpcError,
import {
RpcCallRequest,
RpcCallResponse,
RpcError,
RpcErrorType,
RpcCallInfo,
RpcCallStatus,
@@ -62,16 +62,16 @@ export class RpcCallProxy extends EventEmitter {
private logger = createLogger('RpcCallProxy');
private config: RpcCallProxyConfig;
private networkSender: NetworkSender;
/** 待处理的调用 */
private pendingCalls = new Map<string, RpcCallInfo>();
/** 离线队列 */
private offlineQueue: RpcCallRequest[] = [];
/** 是否在线 */
private isOnline = true;
/** 统计信息 */
private stats: RpcStats = {
totalCalls: 0,
@@ -83,7 +83,7 @@ export class RpcCallProxy extends EventEmitter {
retryCount: 0,
lastUpdated: Date.now()
};
/** 重试定时器 */
private retryTimers = new Map<string, ReturnType<typeof setTimeout>>();
@@ -92,7 +92,7 @@ export class RpcCallProxy extends EventEmitter {
config: Partial<RpcCallProxyConfig> = {}
) {
super();
this.networkSender = networkSender;
this.config = {
defaultTimeout: 30000,
@@ -149,7 +149,7 @@ export class RpcCallProxy extends EventEmitter {
): Promise<TReturn> {
const callId = this.config.generateCallId!();
const timeout = options.timeout || this.config.defaultTimeout;
const request: RpcCallRequest<TArgs> = {
callId,
methodName,
@@ -164,7 +164,7 @@ export class RpcCallProxy extends EventEmitter {
...options
}
};
// 创建Promise和调用信息
return new Promise<TReturn>((resolve, reject) => {
const callInfo: RpcCallInfo<TArgs> = {
@@ -175,16 +175,16 @@ export class RpcCallProxy extends EventEmitter {
retryCount: 0,
createdAt: Date.now()
};
this.pendingCalls.set(callId, callInfo);
this.stats.pendingCalls++;
this.stats.totalCalls++;
// 设置超时
setTimeout(() => {
this.handleTimeout(callId);
}, timeout);
// 发送调用
this.sendCall(callInfo);
});
@@ -199,18 +199,18 @@ export class RpcCallProxy extends EventEmitter {
this.logger.warn(`收到未知调用的响应: ${response.callId}`);
return;
}
// 清理定时器
const timer = this.retryTimers.get(response.callId);
if (timer) {
clearTimeout(timer);
this.retryTimers.delete(response.callId);
}
// 更新状态
callInfo.status = response.success ? RpcCallStatus.COMPLETED : RpcCallStatus.FAILED;
callInfo.completedAt = Date.now();
// 更新统计
if (response.success) {
this.stats.successfulCalls++;
@@ -218,9 +218,9 @@ export class RpcCallProxy extends EventEmitter {
} else {
this.stats.failedCalls++;
}
this.stats.pendingCalls--;
// 处理结果
if (response.success) {
callInfo.resolve!(response.result);
@@ -228,7 +228,7 @@ export class RpcCallProxy extends EventEmitter {
callInfo.reject!(response.error!);
this.emit('callFailed', response.callId, response.error!);
}
// 清理
this.pendingCalls.delete(response.callId);
this.emit('responseReceived', response);
@@ -240,7 +240,7 @@ export class RpcCallProxy extends EventEmitter {
public setOnlineStatus(online: boolean): void {
const wasOnline = this.isOnline;
this.isOnline = online;
if (online && !wasOnline) {
// 从离线状态恢复,处理离线队列
this.processOfflineQueue();
@@ -255,27 +255,27 @@ export class RpcCallProxy extends EventEmitter {
if (!callInfo) {
return false;
}
// 清理定时器
const timer = this.retryTimers.get(callId);
if (timer) {
clearTimeout(timer);
this.retryTimers.delete(callId);
}
// 更新状态
callInfo.status = RpcCallStatus.CANCELLED;
// 拒绝Promise
callInfo.reject!({
type: RpcErrorType.CLIENT_ERROR,
message: '调用被取消'
});
// 清理
this.pendingCalls.delete(callId);
this.stats.pendingCalls--;
return true;
}
@@ -326,16 +326,16 @@ export class RpcCallProxy extends EventEmitter {
for (const callId of pendingCallIds) {
this.cancelCall(callId);
}
// 清理定时器
for (const timer of this.retryTimers.values()) {
clearTimeout(timer);
}
this.retryTimers.clear();
// 清理队列
this.offlineQueue.length = 0;
this.removeAllListeners();
}
@@ -353,7 +353,7 @@ export class RpcCallProxy extends EventEmitter {
}
return;
}
// 构建网络消息
const message = {
type: MessageType.RPC_CALL,
@@ -364,18 +364,18 @@ export class RpcCallProxy extends EventEmitter {
reliable: callInfo.request.options.reliable,
priority: callInfo.request.options.priority
};
// 发送消息
await this.networkSender.sendMessage(message);
callInfo.status = RpcCallStatus.SENT;
callInfo.sentAt = Date.now();
this.emit('callSent', callInfo.request);
} catch (error) {
this.logger.error(`发送RPC调用失败: ${callInfo.request.methodName}`, error);
// 检查是否可以重试
if (callInfo.retryCount < this.config.maxRetries) {
this.scheduleRetry(callInfo);
@@ -396,7 +396,7 @@ export class RpcCallProxy extends EventEmitter {
if (!callInfo || callInfo.status === RpcCallStatus.COMPLETED) {
return;
}
// 检查是否可以重试
if (callInfo.retryCount < this.config.maxRetries) {
this.scheduleRetry(callInfo);
@@ -416,20 +416,20 @@ export class RpcCallProxy extends EventEmitter {
private scheduleRetry<T extends readonly unknown[]>(callInfo: RpcCallInfo<T>): void {
callInfo.retryCount++;
this.stats.retryCount++;
// 计算延迟时间(指数退避)
const baseDelay = this.config.retryDelayBase * Math.pow(this.config.retryDelayMultiplier, callInfo.retryCount - 1);
const delay = Math.min(baseDelay, this.config.maxRetryDelay);
callInfo.nextRetryTime = Date.now() + delay;
this.emit('retryAttempt', callInfo.request.callId, callInfo.retryCount);
const timer = setTimeout(() => {
this.retryTimers.delete(callInfo.request.callId);
this.sendCall(callInfo);
}, delay);
this.retryTimers.set(callInfo.request.callId, timer);
}
@@ -439,13 +439,13 @@ export class RpcCallProxy extends EventEmitter {
private handleCallFailure<T extends readonly unknown[]>(callInfo: RpcCallInfo<T>, error: RpcError): void {
callInfo.status = RpcCallStatus.FAILED;
callInfo.completedAt = Date.now();
callInfo.reject!(error);
this.pendingCalls.delete(callInfo.request.callId);
this.stats.pendingCalls--;
this.stats.failedCalls++;
this.emit('callFailed', callInfo.request.callId, error);
}
@@ -457,7 +457,7 @@ export class RpcCallProxy extends EventEmitter {
// 移除最旧的请求
this.offlineQueue.shift();
}
this.offlineQueue.push(request);
}
@@ -468,10 +468,10 @@ export class RpcCallProxy extends EventEmitter {
if (!this.isOnline || this.offlineQueue.length === 0) {
return;
}
const queue = [...this.offlineQueue];
this.offlineQueue.length = 0;
for (const request of queue) {
try {
// 重新创建调用信息
@@ -481,10 +481,10 @@ export class RpcCallProxy extends EventEmitter {
retryCount: 0,
createdAt: Date.now()
};
this.pendingCalls.set(request.callId, callInfo);
await this.sendCall(callInfo);
} catch (error) {
this.logger.error(`处理离线队列失败: ${request.methodName}`, error);
}
@@ -497,8 +497,8 @@ export class RpcCallProxy extends EventEmitter {
private updateAverageResponseTime(responseTime: number): void {
const totalResponses = this.stats.successfulCalls;
const currentAverage = this.stats.averageResponseTime;
this.stats.averageResponseTime =
this.stats.averageResponseTime =
(currentAverage * (totalResponses - 1) + responseTime) / totalResponses;
}
}
}