From 80668a7ff6bb649361bcbdc78a87b5cbec407a8c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Feb 2026 15:46:59 +0000 Subject: [PATCH] fix: resolve lint errors in ai-decisions worker and test files - Prefix unused `config` variable with underscore in ai-decisions.worker.ts - Replace `as any` type assertions with more specific types in test files https://claude.ai/code/session_01BB9gfSyy86CkdDUZFEpowH --- src/workers/ai-decisions.worker.ts | 41 +++++++++++++++---- tests/data/aiConfig.test.ts | 24 +++++------ .../definitions/definitionValidator.test.ts | 12 ++++-- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/workers/ai-decisions.worker.ts b/src/workers/ai-decisions.worker.ts index db3e6647..339a354b 100644 --- a/src/workers/ai-decisions.worker.ts +++ b/src/workers/ai-decisions.worker.ts @@ -127,7 +127,7 @@ interface ThreatInfo { } // State -let config: AIWorkerConfig = {}; +let _config: AIWorkerConfig = {}; let unitPriorities: Record = DEFAULT_UNIT_PRIORITY; let threatWeights = THREAT_WEIGHTS; let focusFireThreshold = 0.3; @@ -139,7 +139,7 @@ let initialized = false; */ function init(workerConfig: AIWorkerConfig): boolean { try { - config = workerConfig; + _config = workerConfig; unitPriorities = workerConfig.unitPriorities || DEFAULT_UNIT_PRIORITY; threatWeights = workerConfig.threatWeights || THREAT_WEIGHTS; focusFireThreshold = workerConfig.focusFireThreshold ?? 0.3; @@ -282,8 +282,17 @@ function calculateKitePosition( // Random direction if too close const angle = Math.random() * Math.PI * 2; return { - x: Math.max(2, Math.min(mapWidth - 2, unit.x + Math.cos(angle) * unit.attackRange * kiteDistanceMultiplier)), - y: Math.max(2, Math.min(mapHeight - 2, unit.y + Math.sin(angle) * unit.attackRange * kiteDistanceMultiplier)), + x: Math.max( + 2, + Math.min(mapWidth - 2, unit.x + Math.cos(angle) * unit.attackRange * kiteDistanceMultiplier) + ), + y: Math.max( + 2, + Math.min( + mapHeight - 2, + unit.y + Math.sin(angle) * unit.attackRange * kiteDistanceMultiplier + ) + ), }; } @@ -360,7 +369,11 @@ function shouldTransform( if (nearbyGroundEnemies > 0 && nearbyAirEnemies === 0) { return { shouldTransform: true, targetMode: 'assault' }; } - if (nearbyGroundEnemies >= 3 && nearbyAirEnemies <= 1 && groundThreatScore > airThreatScore * 2) { + if ( + nearbyGroundEnemies >= 3 && + nearbyAirEnemies <= 1 && + groundThreatScore > airThreatScore * 2 + ) { return { shouldTransform: true, targetMode: 'assault' }; } } else { @@ -368,7 +381,11 @@ function shouldTransform( if (nearbyAirEnemies > 0 && nearbyGroundEnemies === 0) { return { shouldTransform: true, targetMode: 'fighter' }; } - if (nearbyAirEnemies >= 2 && nearbyGroundEnemies <= 1 && airThreatScore > groundThreatScore * 2) { + if ( + nearbyAirEnemies >= 2 && + nearbyGroundEnemies <= 1 && + airThreatScore > groundThreatScore * 2 + ) { return { shouldTransform: true, targetMode: 'fighter' }; } } @@ -389,7 +406,7 @@ function shouldSwitchTarget( if (unit.targetEntityId === bestTargetId) return false; // Find current target - const currentTarget = enemies.find(e => e.id === unit.targetEntityId); + const currentTarget = enemies.find((e) => e.id === unit.targetEntityId); if (!currentTarget || currentTarget.health <= 0) return true; const currentHealthPercent = currentTarget.health / currentTarget.maxHealth; @@ -398,7 +415,7 @@ function shouldSwitchTarget( if (currentHealthPercent < focusFireThreshold) return false; // Find better target - const betterTarget = enemies.find(e => e.id === bestTargetId); + const betterTarget = enemies.find((e) => e.id === bestTargetId); if (!betterTarget) return false; const betterHealthPercent = betterTarget.health / betterTarget.maxHealth; @@ -465,7 +482,13 @@ function evaluateMicro( // Check if should kite const kite = shouldKite(unit, enemyUnits); if (kite.shouldKite && kite.kiteFromX !== undefined && kite.kiteFromY !== undefined) { - const kitePos = calculateKitePosition(unit, kite.kiteFromX, kite.kiteFromY, mapWidth, mapHeight); + const kitePos = calculateKitePosition( + unit, + kite.kiteFromX, + kite.kiteFromY, + mapWidth, + mapHeight + ); decisions.push({ unitId: unit.id, action: 'kite', diff --git a/tests/data/aiConfig.test.ts b/tests/data/aiConfig.test.ts index 323ae60a..dcb5ae46 100644 --- a/tests/data/aiConfig.test.ts +++ b/tests/data/aiConfig.test.ts @@ -35,7 +35,7 @@ function createTestState(overrides: Partial = {}): AIStateSnaps hard: { targetWorkers: 60 }, very_hard: { targetWorkers: 70 }, insane: { targetWorkers: 80 }, - } as any, + } as FactionAIConfig['difficultyConfig'], }; return { @@ -236,7 +236,11 @@ describe('evaluateCondition', () => { describe('edge cases', () => { it('returns false for unknown condition type', () => { const state = createTestState(); - const condition = { type: 'unknownType', operator: '>', value: 0 } as unknown as RuleCondition; + const condition = { + type: 'unknownType', + operator: '>', + value: 0, + } as unknown as RuleCondition; expect(evaluateCondition(condition, state)).toBe(false); }); @@ -431,9 +435,7 @@ describe('calculateUtilityScore', () => { const state = createTestState({ minerals: 500 }); const utility: UtilityScore = { baseScore: 100, - conditions: [ - { type: 'minerals', operator: '>', value: 400, multiplier: 2 }, - ], + conditions: [{ type: 'minerals', operator: '>', value: 400, multiplier: 2 }], }; expect(calculateUtilityScore(utility, state)).toBe(200); @@ -443,9 +445,7 @@ describe('calculateUtilityScore', () => { const state = createTestState({ minerals: 100 }); const utility: UtilityScore = { baseScore: 100, - conditions: [ - { type: 'minerals', operator: '>', value: 400, multiplier: 2 }, - ], + conditions: [{ type: 'minerals', operator: '>', value: 400, multiplier: 2 }], }; expect(calculateUtilityScore(utility, state)).toBe(100); @@ -468,9 +468,7 @@ describe('calculateUtilityScore', () => { const state = createTestState({ enemyAirUnits: 5 }); const utility: UtilityScore = { baseScore: 100, - conditions: [ - { type: 'enemyAirUnits', operator: '>', value: 0, multiplier: 0.5 }, - ], + conditions: [{ type: 'enemyAirUnits', operator: '>', value: 0, multiplier: 0.5 }], }; expect(calculateUtilityScore(utility, state)).toBe(50); @@ -520,14 +518,14 @@ describe('dominion AI macro rules', () => { const supplyCost = BUILDING_DEFINITIONS.supply_cache.mineralCost; const supplyRules = config!.macroRules.filter( - rule => rule.action.type === 'build' && rule.action.targetId === 'supply_cache' + (rule) => rule.action.type === 'build' && rule.action.targetId === 'supply_cache' ); expect(supplyRules.length).toBeGreaterThan(0); for (const rule of supplyRules) { const mineralCondition = rule.conditions.find( - condition => condition.type === 'minerals' && condition.operator === '>=' + (condition) => condition.type === 'minerals' && condition.operator === '>=' ); expect(mineralCondition).toBeDefined(); expect(mineralCondition!.value).toBeGreaterThanOrEqual(supplyCost); diff --git a/tests/engine/definitions/definitionValidator.test.ts b/tests/engine/definitions/definitionValidator.test.ts index b7e6ed7d..4695cb72 100644 --- a/tests/engine/definitions/definitionValidator.test.ts +++ b/tests/engine/definitions/definitionValidator.test.ts @@ -150,7 +150,7 @@ describe('DefinitionValidator', () => { it('rejects manifest with missing id', () => { const manifest = createValidFactionManifest(); - delete (manifest as any).id; + delete (manifest as Record).id; const result = validator.validateFactionManifest(manifest); expect(result.valid).toBe(false); @@ -822,7 +822,11 @@ describe('DefinitionValidator', () => { it('warns for invalid effect target reference', () => { const { units, buildings, research, abilities } = createTestData(); research.research1.effects = [ - { type: 'damage_bonus', value: 1, targets: ['nonexistent_target'] } as any, + { + type: 'damage_bonus', + value: 1, + targets: ['nonexistent_target'], + } as ResearchDefinition['effects'][number], ]; const result = validator.validateReferences(units, buildings, research, abilities); @@ -874,7 +878,9 @@ describe('DefinitionValidator', () => { it('handles effects without targets', () => { const { units, buildings, research, abilities } = createTestData(); - research.research1.effects = [{ type: 'damage_bonus', value: 1 } as any]; + research.research1.effects = [ + { type: 'damage_bonus', value: 1 } as ResearchDefinition['effects'][number], + ]; const result = validator.validateReferences(units, buildings, research, abilities); expect(result.valid).toBe(true);