Skip to content

refactor: enforce highest coding standards across the project - #3

Draft
ak4dev with Copilot wants to merge 2 commits into
masterfrom
copilot/refactor-project-for-coding-standards
Draft

refactor: enforce highest coding standards across the project#3
ak4dev with Copilot wants to merge 2 commits into
masterfrom
copilot/refactor-project-for-coding-standards

Conversation

Copilot AI commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

The codebase had several quality gaps: prop mutation used as an output channel, fragile regex-based number extraction, no runtime validation on imported state, a non-null assertion at the entry point, and ESLint configured without type-aware rules.

Core logic

  • growthMatrix removed from InvestmentCalculatorProps — it was mutated as an output channel, not used as input. Now a private internal field, reset at the top of each calculateGrowth() call.
  • calculateGrowth() return type changed from string to { formatted: string; numeric: number }, eliminating this pattern at every call site:
    // before
    const totalA = parseInt(calcA.calculateGrowth(show).replace(/[^0-9.-]+/g, ""));
    
    // after
    const totalA = calcA.calculateGrowth(show).numeric;
  • isValidInput() now bounds-checks against MAX_PROJECTED_GAIN / MAX_YEARS_OF_GROWTH; numeric string validation extracted into a private static isValidNumericString() helper.

State import/export

  • isTH4State() type guard added — validates the full TH4State shape before applying imported JSON. Previously any file was blindly applied to state.
  • Timestamp uses date-fns format() instead of manual toISOString().replace(...).slice().

Entry point

  • document.getElementById("root")! replaced with an explicit null guard that throws a descriptive error.

ESLint

  • Upgraded from tseslint.configs.recommended to tseslint.configs.recommendedTypeChecked with parserOptions.project, enabling the full suite of type-aware rules. Two violations surfaced and fixed: explicit number annotation on a recharts callback, and .toString() on a Stitches keyframes reference in a template literal.
Original prompt

Thoroughly evaluate the entire project. After understanding the purpose of everything, refactor such that all of the highest coding standards are enforced. It is imperative that all existing functionality be kept in tact.

Created from VS Code.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: ak4dev <92195328+ak4dev@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor project to enforce highest coding standards refactor: enforce highest coding standards across the project Mar 14, 2026
Copilot AI requested a review from ak4dev March 14, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants