Regression: game.js still holds eight jobs in one 1,862-line scope
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 35/100
- Type d'issue
- Refactorisation
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- javascript
- Domaine
- backend
Piste de recherche
Read js/game.js alongside js/notation.js, js/saved-game.js, and js/rules.js; start with the proposed playersFromPGN and replayUndoStack extractions and add direct unit tests for them. Then review statusForOutcome, describeMove, and the material count, using tests/helpers/load-game.js and npm test as described. Done means steps 1–4 are extracted, each extraction is committed separately, and the full suite passes after each.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
#89 split some UI code out (game-ui.js), but js/game.js is still one 1,862-line script. It shares about 30 mutable top-level lets across eight jobs and is the most-changed file in the repo (74 of the last 200 commits). Several functions in it are pure, or close to pure, and can move out with little risk.
Where
js/game.js:6-56: live state, about 30letsjs/game.js:357-595: review and autoplayjs/game.js:1101-1215: clockjs/game.js:1345-1430: persistence and replayjs/game.js:1599-1764: PGN/FEN export and importjs/game.js:1766-1862: exports, including 15 getters only tests use
Details
The file's own section comments list its jobs: move flow, review and autoplay, ending a game without a move, the computer opponent, the clock, hints, persistence and replay, past games, view models, and PGN/FEN import and export.
Functions here that are pure or nearly pure:
replayUndoStack(start, moves, saved), around line 1400playersFromPGN(text), around line 1720statusForOutcome, around line 717- the material count in
updateCapturedDisplay, around lines 1496-1501 isThreefoldRepetition, around line 1293
Impact
Every recent feature (Redo, the Play button, random side, rebuilding the undo stack on load) had to edit this file and keep all of its globals in mind. Pure logic in it can only be tested by loading the whole page in jsdom (tests/helpers/load-game.js).
Suggested fix
Extract in small PRs, pure code first. Keep the old global name as a one-line alias until its callers move, so every PR leaves the page working.
- Move
playersFromPGNtonotation.js. - Move
replayUndoStacktosaved-game.jsorrules.js, asrebuildUndoStack(start, moves, savedKey). - Move
statusForOutcomeand the move sentence ofdescribeMoveinto a small text module, or intoreview.js. - Move the material count into
rules.jsasmaterialBalance(board). - Only then consider extracting the clock section behind an object that
game.jsowns.
Acceptance criteria
- Before starting: unit tests that call
replayUndoStackandplayersFromPGNdirectly, and characterization tests for thedescribeMovetext of castling, en passant, promotion and check. - Each extraction is its own commit, and the full suite passes after each one.
-
game.jsloses steps 1-4.
Getting started
- Relevant files:
js/game.js,js/notation.js,js/saved-game.js,js/rules.js,tests/helpers/load-game.js - How to run tests:
npm test
Regression of #89.
Filed by repo-audit/full-audit at 01c6a35. Severity: medium. Effort: L. audit-key: tech-debt|js/game.js|module-structure
- Langage dominant
- JavaScript
- Étoiles
- 4
- Forks
- 2
- Merge moyen
- 22 h 16 min
- PR mergées (30 j)
- 9
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de TMHSDigital/Static_Chess
-
enhancement help wanted severity: low
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
TMHSDigital/Static_Chess#184 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement help wanted severity: low
Difficulté 4/5 3-5 jours Accessibilité débutants 58/100
TMHSDigital/Static_Chess#182 ·
Les mainteneurs répondent en général sous 1 jour
-
help wanted severity: medium tech-debt
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
TMHSDigital/Static_Chess#173 ·
Les mainteneurs répondent en général sous 1 jour
-
help wanted performance severity: medium
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
TMHSDigital/Static_Chess#168 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement help wanted severity: low
Difficulté 4/5 3-5 jours Accessibilité débutants 61/100
TMHSDigital/Static_Chess#161 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de TMHSDigital/Static_Chess
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
cytoscape/cytoscape.js#3597 ·
Les mainteneurs répondent en général sous 5 jours
-
priority: low server testing
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
blamechris/chroxy#9277 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
sunososobro-hub/cloudball#191 ·
Les mainteneurs répondent en général sous 1 jour
-
[MCP]: page snapshots in .playwright-mcp/ are not git-ignored (.playwright-cli/ is, since #42318)Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
microsoft/playwright#44289 ·
Les mainteneurs répondent en général sous 1 jour
-
Wire ISO post: has() accepts text values such as an empty string, true or 0x1A for wire numbersOuvertearea:post effort:low enhancement P7 source:agent
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour