Skip to content

feat: add "Apply Fix" and "Apply Suggestion" buttons with html-eslint #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HyzeahAchungha
Copy link

FEATURE Add Apply Fix and Apply Suggestion

Added event listeners for #applyFixBtn and #applySuggestionBtn

Used Linter.verifyAndFix() and Linter.verify() from html-eslint for linting and suggesting

Updated the code editor with the modified code when fixes/suggestions are applied

Displayed success or info messages in #lintOutput

This PR implements the "Apply Fix" and "Apply Suggestion" buttons in the application interface. It integrates the html-eslint parser and linter to:

Automatically apply ESLint auto-fixes to the user’s code

Allow users to apply suggested fixes manually if available

Display feedback messages to inform users whether fixes or suggestions were applied

@HyzeahAchungha HyzeahAchungha changed the title FEATURE Add Apply Fix and Apply Suggestion feat: add "Apply Fix" and "Apply Suggestion" buttons with html-eslint May 30, 2025
@yeonjuan yeonjuan requested a review from Copilot June 1, 2025 11:33
Copy link
Contributor

@Copilot 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.

Pull Request Overview

This PR adds "Apply Fix" and "Apply Suggestion" buttons to the code editor interface, integrating html-eslint for automated linting and code suggestions.

  • Implements event listeners for applying fixes and suggestions
  • Introduces helper methods (getLintConfig and applyFix) for handling lint configuration and applying fixes
  • Adjusts the layout and HTML to load the updated app script

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

File Description
packages/website/src/scripts/playground/app.js Implements new linting functionality and buttons for applying fixes/suggestions
packages/website/src/scripts/layout.js Minor formatting update
packages/website/src/index.html Adds script tag to load the updated playground app

this.handleCodeChange(this.view.codeEditor);
this.handleConfigChange(this.view.configEditor);
this.handleLanguageChange();

// Setup fix/suggestion buttons
const applyFixBtn = document.getElementById("applyFixBtn");
Copy link
Preview

Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

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

Consider adding null checks for 'applyFixBtn', 'applySuggestionBtn', and 'lintOutput' elements to handle cases where these elements might not exist, preventing potential runtime errors.

Copilot uses AI. Check for mistakes.


applySuggestionBtn.addEventListener("click", () => {
const code = this.view.codeEditor.getValue();
const eslintConfig = this.getLintConfig();
Copy link
Preview

Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

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

Silently returning an empty config in getLintConfig() may hide invalid JSON configurations; consider logging the error or notifying the user to improve debuggability.

Copilot uses AI. Check for mistakes.

Comment on lines +75 to +77
const newCode = this.applyFix(code, suggestion.fix);
this.view.codeEditor.setValue(newCode);
lintOutput.textContent = `✅ Applied suggestion: ${suggestion.desc}`;
Copy link
Preview

Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

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

Ensure that 'suggestion.fix' is defined before applying the fix, as some suggestions might not include an auto-fix, which could lead to runtime errors.

Suggested change
const newCode = this.applyFix(code, suggestion.fix);
this.view.codeEditor.setValue(newCode);
lintOutput.textContent = `✅ Applied suggestion: ${suggestion.desc}`;
if (suggestion.fix) {
const newCode = this.applyFix(code, suggestion.fix);
this.view.codeEditor.setValue(newCode);
lintOutput.textContent = `✅ Applied suggestion: ${suggestion.desc}`;
} else {
lintOutput.textContent = "ℹ️ No fix available for the selected suggestion.";
}

Copilot uses AI. Check for mistakes.

@yeonjuan yeonjuan self-requested a review June 1, 2025 11:37
Copy link
Owner

@yeonjuan yeonjuan left a comment

Choose a reason for hiding this comment

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

@HyzeahAchungha Thank you for your contribution! I've left a review.

Copy link
Owner

Choose a reason for hiding this comment

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

Hi @HyzeahAchungha This project does not use package-lock.json. Could you please remove this file?

Comment on lines +1 to +13
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code Playground</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/mode/htmlmixed/htmlmixed.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/mode/javascript/javascript.min.js"></script>
<!-- ESLint for real linting and auto-fix -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/eslint/8.56.0/eslint.min.js"></script>
Copy link
Owner

Choose a reason for hiding this comment

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

Since layout.html is used as a template via posthtml, the html & head & body tag is unnecessary. Also, codemirror is already specified in package.json, so there's no need to include it via CDN. Could you please remove these parts?

}
if ($openTarget || $closeTarget) {

<script type="module">
Copy link
Owner

Choose a reason for hiding this comment

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

Could you move the JavaScript code to packages/website/src/scripts/playground/app.js and remove the inline script?

Copy link
Owner

Choose a reason for hiding this comment

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

There were no changes to the dependencies, so there shouldn’t be any modifications to the yarn.lock file. Could you please exclude it from the commit?

@HyzeahAchungha
Copy link
Author

HyzeahAchungha commented Jun 1, 2025 via email

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