Skip to content

Refactor: eliminate code duplication and fix script syntax error#6

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/check-for-bad-code
Draft

Refactor: eliminate code duplication and fix script syntax error#6
Copilot wants to merge 2 commits intomainfrom
copilot/check-for-bad-code

Conversation

Copy link

Copilot AI commented Nov 9, 2025

Identified and fixed code quality issues: duplicate state serialization logic, duplicate default values, unused files, and a malformed script tag causing parse errors.

Changes

Extracted state cloning helper (~30 lines eliminated)

  • Three identical JSON.parse(JSON.stringify({...})) blocks in saveStateToHistory(), undo(), and redo() now use shared cloneState() function

Centralized default state (~66 lines eliminated)

  • Default values duplicated between state initialization and resetToDefaults() now reference single DEFAULT_STATE constant

Fixed script syntax error

  • Removed trailing </script> tag from app.js that caused JavaScript parse errors when loaded as external script

Removed unused file

  • Deleted /js/app.js (1,368 lines) - never referenced in any HTML

Example

Before:

function saveStateToHistory() {
    const stateCopy = JSON.parse(JSON.stringify({
        imageTransform: state.imageTransform,
        imageFilters: state.imageFilters,
        // ... 13 more properties
    }));
    // ...
}

function undo() {
    const currentState = JSON.parse(JSON.stringify({
        imageTransform: state.imageTransform,
        imageFilters: state.imageFilters,
        // ... 13 more properties (identical)
    }));
    // ...
}

After:

function cloneState() {
    return JSON.parse(JSON.stringify({
        imageTransform: state.imageTransform,
        // ... all properties
    }));
}

function saveStateToHistory() {
    const stateCopy = cloneState();
    // ...
}

function undo() {
    const currentState = cloneState();
    // ...
}

Net impact: -1,454 lines, no functional changes

Original prompt

Is there any bad 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.

@I-794 I-794 requested a review from Copilot November 9, 2025 03:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ipt tag issue

Co-authored-by: I-794 <147570875+I-794@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate and report on bad code practices Refactor: eliminate code duplication and fix script syntax error Nov 9, 2025
Copilot AI requested a review from I-794 November 9, 2025 03:43
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.

3 participants