Repository navigation
Closed
Labels
help wantedExtra attention is neededseverity: lowMinor polishtech-debtRefactoring and maintainability
Description
Summary
A checklist of small leftovers and duplicates across the js/ modules. Each was read in place. One of them is a visible inconsistency: an armed "Discard game?" prompt on New Game survives a move, where an armed "Resign?" is cancelled.
Where and what
- Two confirm-on-second-click implementations. New Game has its own (
resetConfirmTimer,handleResetClick,cancelResetConfirm,js/game.js:1475); Resign and Load useconfirmSecondClick(js/game.js:559).cancelConfirms()(js/game.js:584) runs on every move, undo and game end but does not know about the New Game button. Route New Game throughconfirmSecondClick, delete the private copy, and renameRESET_CONFIRM_MS(js/config.js:96), which times all three buttons. - Three ways to reach localStorage.
saveToLocalStorageandloadFromLocalStorageinjs/utils.js:90andjs/utils.js:108(unused by the app), thereadSettingandwriteSettingclosures injs/main.js:17, and raw try/catch blocks injs/game.js:1097andjs/game.js:1260. Pick one helper. - Helpers used only by tests.
deepClone(js/utils.js:60),algebraicToCoords,generateAllLegalMoves(js/game.js:1013),canCastleand theisPromotionPendingalias. Delete them or move them to the test helper, and drop them fromappGlobalsineslint.config.mjs. - Two "can this side mate" rules in two layers.
canDeliverMateinjs/game.js:909(flag fall) andhasInsufficientMaterialinjs/rules.js:312. They disagree on same-shade bishops. Move the first intorules.jsnext to the second. - Redundant
windowexports.js/promotion.js:117assigns three functions towindowthat nothing reads;js/drag.js:22re-exportsdragJustEnded, whichjs/game.js:159then reads throughwindowwith atypeofguard. -
drag.jsreadsgame.jsstate variables directly (js/drag.js:97) where the architecture document says it uses functions. - Castling rights are re-derived from
hasMovedflags in three places injs/rules.js(lines 155, 284, 404). One helper would do. - Stale comments and dead lines.
js/pieces.js:113saysgame.jsadds castling throughcanCastle();js/pieces.js:123"Add functions here...";js/game.js:8describes a move record without its current fields;js/game.js:1716says "basic disambiguation";js/board.js:287is commented-out code; theboardStateparameter ofupdateBoardVisuals(js/board.js:223) is unused. - Tunables outside
CONFIG.AI_DRAW_MARGIN(js/game.js:68), the low-time threshold20000(js/game.js:859), the button flash1500(js/game.js:1578), the drag threshold and click-swallow time injs/drag.js. - Theme values and timings duplicated between CSS and
config.js(css/style.css:632,js/config.js:50,css/pieces.css:61,js/config.js:100). - Leftover lint ignores for Playwright output in
eslint.config.mjs:135; Playwright is not a dependency. - The FEN download fallback uses the PGN MIME type (
js/game.js:1582,application/x-chess-pgnfor a.fenfile).
Steps to reproduce (the confirm drift)
Against the computer: play a move, click New Game once, and let the computer reply within four seconds. The button still reads "Discard game?" and the next click discards the game. Do the same with Resign: the reply resets the button.
Acceptance criteria
- Each box above is ticked or closed with a reason.
- A test shows a move cancels an armed New Game prompt, matching the Resign test.
-
npm run lintandnpm testpass.
Related: #30
Getting started
- Relevant files:
js/game.js,js/utils.js,js/main.js,js/rules.js,js/drag.js,js/promotion.js,eslint.config.mjs - How to run tests:
npm ci, thennpm test - Each box can be its own small pull request.
Filed by repo-audit/full-audit at ac3afa3. Severity: low. Effort: M. audit-key: tech-debt|js/game.js|leftovers-and-duplicates
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededseverity: lowMinor polishtech-debtRefactoring and maintainability
Activity
TMHSDigital commentedon Nov 15, 2026
Done in the commit that closed this issue ("Clear out leftovers and duplicates across the js/ modules"). Each box, ticked or closed with a reason:
confirmSecondClick;resetConfirmTimer,RESET_LABELandcancelResetConfirmare gone, socancelConfirms()now covers it.RESET_CONFIRM_MSis renamedCONFIRM_MS.readStored,writeStoredandremoveStoredinutils.jsare the one helper;main.jsandgame.jsuse them andsaveToLocalStorage/loadFromLocalStorageare deleted.deepClone,canCastleand theisPromotionPendingalias are deleted (the tests callrules.canCastleIndirectly). Kept, because app code now uses them:algebraicToCoords(reading FEN) andgenerateAllLegalMoves(a loaded position that is already decided).canDeliverMateis inrules.jsnext tohasInsufficientMaterialand now also says no for bishops that all stand on one colour.windowexports. The three inpromotion.jsare removed.dragJustEndedstays onwindow: it is the one documented shared flag and the drag tests read it there;game.jsnow reads it without thetypeofguard.drag.jsreadsgame.jsstate. Ticked. It calls a newisOwnPiece(row, col);boardStateandcurrentPlayerare no longer shared names ineslint.config.mjs.hasCastlingRight(board, color, side)servescanCastleIn,positionKeyandpositionToFEN.pieces.js, the move-record comment ingame.js, the commented-out line inboard.jsand the unusedboardStateparameter ofupdateBoardVisuals. The "basic disambiguation" comment went with SAN disambiguation counts pinned pieces, so moves get an unneeded file or rank #99.CONFIG. Ticked:AI_DRAW_MARGIN,AI_HURRY_BELOW_MS,NOTICE_MS,DRAG_THRESHOLD_PX,DRAG_CLICK_GUARD_MS; the low-time colour usesLOW_TIME_WARNINGS.config.js. Closed with a reason: the stylesheet has to carry the defaults so the first paint is right before any script runs, and there is no build step to generate one from the other. Two new tests intests/unit/themes.test.jsfail if the copies drift apart..gitignore, and.playwright-mcp/is real local output of browser checks on this repository..fenfile is offered astext/plain.Verified: a new test in
tests/unit/controls.test.jsarms "Discard game?", lets the computer reply, and checks the button is back to "New Game" and that the next click asks again; it failed on the code before this change ("Discard game?" still showing). Further tests cover the storage helpers including blocked storage,canDeliverMate, and the file types. The perft counts and FEN round trips pass with the castling helper. Full suite,npm run lintand the format check pass.Clear out leftovers and duplicates across the js/ modules (TMHSDigita…