Replace script-order globals shared between board.js, game.js and drag.js

Đang mở
#32 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
eslint, javascript, node.js

Hướng nghiên cứu

Read docs/ARCHITECTURE.md and .github/CONTRIBUTING.md, then trace the shared state and window accessors in js/board.js, js/game.js, and js/drag.js alongside the globals in eslint.config.js. Start by checking the test bootstrap work in related issue #40 and the existing tests in tests/. Run npm test and npm run lint; done means board rendering no longer reads game variables, missing drag dependencies raise errors, and the per-file globals list shrinks or disappears.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

severity: medium tech-debt

Summary

The seven scripts share one global scope and depend on load order. board.js and game.js read each other's variables, drag.js reaches both through window.* behind typeof guards, and eslint.config.js hand-lists the cross-file globals for every file.

Where

  • js/board.js:184 (reads moveHistory from game.js), js/game.js:109 (reads selectedSquare and possibleMoves from board.js)
  • js/game.js:908-921, js/board.js:252-266 (window getters)
  • js/drag.js:97-115, js/drag.js:230-232, js/drag.js:256
  • eslint.config.js:35-155
  • package.json:5 ("type": "module" while every file uses CommonJS exports)

Impact

Adding or moving a function means editing the source, the ESLint globals list and each test preamble. The typeof guards in drag.js turn a wiring mistake into a silent no-op (a drop that does nothing). The globals list is already stale: drag.js is granted handleBoardClick, which it does not use.

Suggested fix

  1. Move the shared test bootstrap into one helper (#40); no production change.
  2. Break the cycle: pass lastMove into updateBoardVisuals, and give selectedSquare and possibleMoves one owning module with accessors.
  3. Replace the window.* getters with one explicit namespace object and drop the typeof guards.
  4. Optionally convert to ES modules, which removes the per-file globals lists. ES modules do not load from file://, so decide first whether opening index.html directly must keep working.

Acceptance criteria

  • board.js renders without reading game.js variables
  • A missing dependency in drag.js raises an error instead of doing nothing
  • The per-file globals in eslint.config.js shrink or disappear

Getting started

  • Relevant files: js/board.js, js/game.js, js/drag.js, eslint.config.js, tests/
  • How to run tests: npm install, then npm test and npm run lint
  • Related docs: docs/ARCHITECTURE.md, .github/CONTRIBUTING.md

Filed by repo-audit/full-audit at 8a2c86c. Severity: medium. Effort: M. audit-key: tech-debt|js/board.js|window-globals

Ngôn ngữ chính
JavaScript
Star
4
Fork
2
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TMHSDigital/Static_Chess

Tất cả issue của TMHSDigital/Static_Chess

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.