Skip to content

Commit 9c5846f

Browse files
committed
refactor(client): 开启 noUnusedLocals 并清理 10 处死代码,生产代码 any 清零
1 parent 807a068 commit 9c5846f

15 files changed

Lines changed: 54 additions & 39 deletions

File tree

‎client/.oxlintrc.json‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
{
2-
"$schema": "./node_modules/oxlint/configuration_schema.json",
3-
"plugins": ["react", "typescript", "oxc"],
4-
"rules": {
5-
"react/rules-of-hooks": "error",
6-
"react/only-export-components": ["warn", { "allowConstantExport": true }]
7-
}
8-
}
1+
{
2+
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"plugins": ["react", "typescript", "oxc"],
4+
"rules": {
5+
"react/rules-of-hooks": "error",
6+
"react/only-export-components": ["warn", { "allowConstantExport": true }],
7+
"typescript/no-explicit-any": "warn",
8+
"no-unused-vars": "warn",
9+
"react-hooks/exhaustive-deps": "warn"
10+
},
11+
"overrides": [
12+
{
13+
"files": ["**/*.test.{ts,tsx}", "**/test/**/*.{ts,tsx}"],
14+
"rules": {
15+
"typescript/no-explicit-any": "off"
16+
}
17+
}
18+
]
19+
}

‎client/electron/ipcUtils.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ export function getMainWindowId(): number | null {
5151
* 支持类型安全的 handler 签名:
5252
* 允许 handler 声明具体参数类型,内部通过断言适配 ipcMain.handle 的 unknown[] 签名。
5353
*/
54-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
55-
type TypedHandler<T extends any[]> = (
54+
type TypedHandler<T extends unknown[]> = (
5655
event: Electron.IpcMainInvokeEvent,
5756
...args: T
5857
) => Promise<unknown>;
@@ -73,7 +72,7 @@ type TypedHandler<T extends any[]> = (
7372
* @param handler - 处理函数
7473
* @ai-context main.ts 中所有 safeHandle 调用均经过此函数
7574
*/
76-
export function safeHandle<T extends any[]>(
75+
export function safeHandle<T extends unknown[]>(
7776
channel: string,
7877
handler: TypedHandler<T>,
7978
): void {
@@ -147,7 +146,7 @@ export function requireArray<T = unknown>(value: unknown, field: string): T[] {
147146
* @param handler - 实际处理函数(仅处理最后一次请求的参数)
148147
* @ai-context 用于高频 IPC 场景(如滚动位置同步、窗口状态更新)
149148
*/
150-
export function safeHandleBatched<T extends any[]>(
149+
export function safeHandleBatched<T extends unknown[]>(
151150
channel: string,
152151
handler: TypedHandler<T>,
153152
): void {

‎client/src/features/constellation/lib/evolutionData.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ interface ReviewIndex {
7979
export function deriveEvolutionData(
8080
graph: KnowledgeGraph,
8181
reviews: Array<{ cardId: string; reviewedAt: Date | string }> = [],
82-
sourceRefs: Map<string, string> = new Map(),
82+
// 兼容历史调用签名:本函数不使用 sourceRefs(映射在 buildEvolutionData 中消费),
83+
// 下划线前缀避免 noUnusedParameters 报错,保持公共 API 不变
84+
_sourceRefs: Map<string, string> = new Map(),
8385
now: number = Date.now(),
8486
): EvolutionData {
8587
if (graph.coldStart || graph.nodes.length === 0) {

‎client/src/features/inspiration/lib/constellationLayout.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ function isInCenterExclusion(
188188
* @ai-context 为中心创作区留出视觉空间,光点被推到左右两侧
189189
*/
190190
function redistributeFromCenter(
191-
x: number,
192-
y: number,
191+
// 历史签名保留 x/y(调用处按位置传参),实现只用 seed 与 exclusion 重算横向位置
192+
_x: number,
193+
_y: number,
193194
seed: number,
194195
exclusion: NonNullable<LayoutOptions['centerExclusion']>,
195196
): number {

‎client/src/features/pomodoro/store/tickSlice.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ function runPhaseCompletion(
243243
* 避免墙钟校准跳变时漏报。
244244
*/
245245
function emitPhaseSignals(
246-
get: () => PomodoroState,
246+
// 历史签名保留 get(调用处按位置传参),实现只读 set 与阶段参数
247+
_get: () => PomodoroState,
247248
set: (fn: (s: PomodoroState) => Partial<PomodoroState>) => void,
248249
phase: Phase,
249250
nextRemaining: number,

‎client/src/hooks/useLearningProgress.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function useLearningProgress(): LearningProgressItem[] {
7373
try {
7474
const allCards = await db.flashcards.toArray();
7575
if (allCards.length > 0) {
76-
const reviewedCards = allCards.filter((c: any) => c.repetitions > 0);
76+
const reviewedCards = allCards.filter((c) => c.repetitions > 0);
7777
const flashcardProgress = Math.min(100, Math.round((reviewedCards.length / allCards.length) * 100));
7878
result.push({ subject: '闪卡复习', progress: flashcardProgress });
7979
} else {

‎client/src/lib/3d/core/ContextRecovery.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function ContextRecovery({ onContextLost }: { onContextLost?: () => void
4949
console.log('[WebGL] Context restored');
5050
// 强制重新编译所有着色器
5151
try {
52-
const info = (gl as any).info;
52+
const info = (gl as unknown as { info?: { programs?: Array<{ destroy?: () => void }> } }).info;
5353
if (info?.programs) {
5454
// WebGLRenderer 旧 info 结构:info.programs 为数组
5555
(info.programs as Array<{ destroy?: () => void }>)?.forEach((program) => {

‎client/src/lib/3d/core/MemoryManager.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ export function MemoryManager() {
4343
// 定期报告内存使用
4444
useEffect(() => {
4545
const interval = setInterval(() => {
46-
const info = gl.info as any;
46+
const info = gl.info as unknown as {
47+
memory?: { geometries?: number; textures?: number; programs?: number };
48+
programs?: { length?: number };
49+
};
4750
const programs = info.memory?.programs ?? info.programs?.length ?? 0;
48-
if (info.memory.geometries > 500 || info.memory.textures > 100) {
51+
const geometries = info.memory?.geometries ?? 0;
52+
const textures = info.memory?.textures ?? 0;
53+
if (geometries > 500 || textures > 100) {
4954
console.warn('[3D Memory]', {
50-
geometries: info.memory.geometries,
51-
textures: info.memory.textures,
55+
geometries,
56+
textures,
5257
programs,
5358
});
5459
}

‎client/src/lib/3d/shaders/gpuParticleShaders.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export function patchParticleShader(
7777
};
7878

7979
// 保存引用以便在 useFrame 中更新 uniform
80-
(material as any).__gpuParticleUniforms = uniforms;
80+
// (自定义属性挂载:three 未公开该扩展点,用受约束的接口声明替代 any)
81+
(material as unknown as { __gpuParticleUniforms: Record<string, THREE.IUniform> }).__gpuParticleUniforms = uniforms;
8182
}
8283

8384
/**
@@ -87,7 +88,7 @@ export function updateGPUParticleUniforms(
8788
material: THREE.PointsMaterial,
8889
time: number,
8990
): void {
90-
const uniforms = (material as any).__gpuParticleUniforms as Record<string, THREE.IUniform> | undefined;
91+
const uniforms = (material as unknown as { __gpuParticleUniforms?: Record<string, THREE.IUniform> }).__gpuParticleUniforms;
9192
if (uniforms) {
9293
uniforms.uTime.value = time;
9394
}

‎client/src/lib/ai/RemoteAIPlugin.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ import {
3737
* AIPlugin 门面与流式 postStream 调用,公共 API 与拆分前一致。
3838
*/
3939
export class RemoteAIPlugin implements AIPlugin {
40-
/** 保留字段:历史构造签名兼容(超时实际由 aiClient 统一控制) */
41-
private timeout: number;
42-
43-
constructor(timeout: number = 60000) {
44-
this.timeout = timeout;
45-
}
40+
constructor(
41+
// 历史构造签名兼容:超时实际由 aiClient 统一控制,不再消费该参数
42+
_timeout: number = 60000,
43+
) {}
4644

4745
// ── 非流式功能(委托域模块) ─────────────────────────
4846

0 commit comments

Comments
 (0)