[priority: high] Duplicate functions across files (calculateDesignTime, calculateDesignCapacityCost, generateSwarmEnemies) #100
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: High — duplicated code risks divergence, wastes maintenance effort, and indicates unclear module ownership.
Findings:
calculateDesignTimedefined identically in bothcrafting-design.tsandcrafting-utils.tscalculateDesignCapacityCostduplicated acrosscrafting-design.ts,crafting-utils.ts, andEnchantmentDesigner/utils.ts(with different signatures)generateSwarmEnemiesimplemented identically in bothenemy-utils.tsandroom-utils.ts(93% near-duplicate)Affected files:
src/lib/game/crafting-design.ts,src/lib/game/crafting-utils.tssrc/components/game/crafting/EnchantmentDesigner/utils.tssrc/lib/game/utils/enemy-utils.ts,src/lib/game/utils/room-utils.tsSuggested fix: Consolidate to single canonical sources. Remove duplicates and import from the canonical module. Give different-signature variants distinct names to avoid confusion.
Confidence: High
Dimension: convention_outlier (score: 58.0%)
Starting work on consolidating duplicate functions. Will investigate the three duplicate pairs and consolidate to canonical sources.
Fix complete. Consolidated all three duplicate function pairs:
calculateDesignCapacityCost— Removed duplicate fromcrafting-utils.ts.EnchantmentDesigner/utils.tsnow delegates to canonicalcrafting-design.tsversion.calculateDesignTime— Removed duplicate fromcrafting-utils.ts.EnchantmentDesigner/utils.tsnow delegates to canonicalcrafting-design.tsversion.generateSwarmEnemies— Enhancedenemy-utils.tsversion with barrier support (matching the more completeroom-utils.tsvariant), removed duplicate fromroom-utils.ts, which now imports fromenemy-utils.ts.Result: 5 files changed, 27 insertions(+), 57 deletions(-). Build passes, all pre-commit checks pass. No new TypeScript errors introduced.
Issue resolved. All three duplicate function pairs consolidated to canonical sources. Commit:
53b3a94