Skip to content
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

Change Request: Notify plugins when a fix has been applied #16143

Closed
1 task done
Jason3S opened this issue Jul 18, 2022 · 3 comments
Closed
1 task done

Change Request: Notify plugins when a fix has been applied #16143

Jason3S opened this issue Jul 18, 2022 · 3 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint needs design Important details about this change need to be discussed
Projects

Comments

@Jason3S
Copy link

Jason3S commented Jul 18, 2022

ESLint version

v8.20.0

What problem do you want to solve?

Context

As the author of the spellchecker plugin: @cspell/eslint-plugin, I would like to present the user a "fix" that allows the user to add a word to their custom dictionary. See: CSpell ESLint Plugin: Configuration option to add words to the dictionary · Issue #3233.

When used with an editor extension like VS Code ESLint, something like the following would show up:

image

If the fix is applied, the spellchecker plugin would add the word to the custom dictionary.

Problem

In the current ESLint implementation, a ReportFixer does not have the ability to provide a custom fix action or to know if a fix has been applied so it can take a custom action.

What do you think is the correct solution?

Two options came to mind:

  1. context provides an event emitter than can be listen to:
    context.onFixApplied((fix) => console.log(fix));
    This provides the ability of any extension to listen for fixes and take an action.
  2. Add an optional applied function to Fix that is called when a fix has been applied.
    This is the easiest fix:
    // Make output to this fix.
    output += text.slice(Math.max(0, lastPos), Math.max(0, start));
    output += fix.text;
    lastPos = end;
    return true;

    Becomes something like this:
    output += text.slice(Math.max(0, lastPos), Math.max(0, start));
    output += fix.text;
    fix?.applied();
    lastPos = end;

Participation

  • I am willing to submit a pull request for this change.

Additional comments

No response

@Jason3S Jason3S added core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint triage An ESLint team member will look at this issue soon labels Jul 18, 2022
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Jul 18, 2022
@nzakas
Copy link
Member

nzakas commented Jul 20, 2022

Interesting idea, though I’m actually not sure about the timing aspect as fixes are applied after linting is complete.

However, if you’d like to do some research and put together an RFC, we can certainly consider it.

@nzakas nzakas added needs design Important details about this change need to be discussed and removed triage An ESLint team member will look at this issue soon labels Jul 20, 2022
@nzakas nzakas moved this from Needs Triage to Waiting for RFC in Triage Jul 20, 2022
@github-actions
Copy link

Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update.

@github-actions github-actions bot added the Stale label Sep 18, 2022
@Jason3S
Copy link
Author

Jason3S commented Sep 19, 2022

@nzakas,

Thank you. I'll file an RFC.

@nzakas nzakas moved this from Waiting for RFC to RFC Opened in Triage Sep 19, 2022
@github-actions github-actions bot removed the Stale label Sep 19, 2022
@Jason3S Jason3S closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2022
Triage automation moved this from RFC Opened to Complete Oct 13, 2022
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Apr 12, 2023
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint needs design Important details about this change need to be discussed
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests

2 participants