Skip to content

Conversation

@yeonjuan
Copy link
Owner

@yeonjuan yeonjuan commented Aug 5, 2025

Checklist

Description

@yeonjuan yeonjuan marked this pull request as ready for review August 6, 2025 13:02
@yeonjuan yeonjuan requested a review from Copilot August 6, 2025 13:02
Copy link
Contributor

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 autofix functionality to the playground by implementing apply fix and apply suggestion buttons for ESLint messages. The changes enable users to automatically apply ESLint fixes and suggestions directly from the error display.

  • Added UI buttons for applying fixes and suggestions to lint messages
  • Implemented backend logic to apply fixes and suggestions by modifying the code editor content
  • Enhanced the error display with better styling and overflow handling

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
packages/website/src/scripts/playground/view.js Added error element caching and redesigned lint message HTML with fix/suggestion buttons
packages/website/src/scripts/playground/model.js Implemented applyFix and applySuggestion methods with autofixed event handling
packages/website/src/scripts/playground/app.js Added event listeners for autofix buttons and autofixed event handling
packages/website/src/components/playground.html Added overflow scroll to error container and removed placeholder text

<a href="/docs/rules/${rule}" class="ml-1 hover:underline">(${rule})</a>
</span>
<div class="ml-auto mr-0 my-2">
${fix? html`<button class="bg-accent text-white px-4 py-1 rounded hover:opacity-80 w-max">apply fix</button>`: ""}
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

Missing space after the ternary operator condition. Should be ${fix ? html... : ""}

Copilot uses AI. Check for mistakes.
code.slice(end);
this.setCode(fixed);
this.lint();
this.notify('autofixed')
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

Missing semicolon at the end of the statement. JavaScript best practices recommend consistent semicolon usage.

Suggested change
this.notify('autofixed')
this.notify('autofixed');

Copilot uses AI. Check for mistakes.
const fixed = code.slice(0, start) +
suggestion.fix.text +
code.slice(end);
this.setCode(fixed);
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

Trailing whitespace at the end of the line should be removed.

Copilot uses AI. Check for mistakes.
const $button = event.target.closest("button");
if ($button) {
const $li = $button.closest("li");
const index = Array.from($li.parentNode.children).indexOf($li);
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

This approach to find the message index is fragile and could break if the DOM structure changes. Consider storing the message index as a data attribute on the list item instead.

Suggested change
const index = Array.from($li.parentNode.children).indexOf($li);
const index = $li.dataset.index ? parseInt($li.dataset.index, 10) : -1;

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +52
const $li = $button.closest("li");
const index = Array.from($li.parentNode.children).indexOf($li);
const message = this.model.messages[index];
if ($button.textContent.includes("fix")) {
this.model.applyFix(message);
} else if ($button.textContent.includes("suggestion")) {
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

Using textContent to determine button action is brittle and could break with internationalization or text changes. Consider using data attributes or CSS classes to identify button types.

Suggested change
const $li = $button.closest("li");
const index = Array.from($li.parentNode.children).indexOf($li);
const message = this.model.messages[index];
if ($button.textContent.includes("fix")) {
this.model.applyFix(message);
} else if ($button.textContent.includes("suggestion")) {
// NOTE: Buttons must have a data-action attribute set to "fix" or "suggestion"
const $li = $button.closest("li");
const index = Array.from($li.parentNode.children).indexOf($li);
const message = this.model.messages[index];
if ($button.dataset.action === "fix") {
this.model.applyFix(message);
} else if ($button.dataset.action === "suggestion") {

Copilot uses AI. Check for mistakes.
@yeonjuan yeonjuan merged commit 9d00cec into main Aug 6, 2025
3 checks passed
@yeonjuan yeonjuan deleted the fix/352 branch August 6, 2025 13:09
@codecov
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.53%. Comparing base (e75bca7) to head (230215d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #397   +/-   ##
=======================================
  Coverage   98.53%   98.53%           
=======================================
  Files          82       82           
  Lines        2658     2658           
  Branches      736      736           
=======================================
  Hits         2619     2619           
  Misses         39       39           
Flag Coverage Δ
unittest 98.53% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

[FEATURE] Add "Apply Fix" and "Apply Suggestion" buttons to the playground

2 participants