-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
New: Suggestions #30
New: Suggestions #30
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your proposal.
I failed to read how this RFC changes public APIs. Would you elaborate about it?
Thanks for the RFC! I guess my main question is... Why do suggestions need to be separate from autofixes? Could we just add an attribute to autofixes which says whether it's a suggestion or meant to be a safe autofix? What value do suggestions add that autofix does not or cannot provide via an enhancement to autofix? |
There may be many suggestions per rule error, none of them should be applied automatically at any point. That behavior feels different enough to me to make it into it's own thing, and not try to piggy back on autofixes. |
@mysticatea I updated PR with your suggestions and some additional changes. Please take a look when you have a chance. CC: @gaearon |
Could you give an example of a case where there would be many suggestions for a rule error? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the update.
I have more some suggestions.
- About how editor integrators use the
suggestions
properties. - About processors which don't support autofix.
I have one example, no-useless-escape rule. We have given up fixing the errors of no-useless-escape rule because it can be two cases. We can use suggestions for that.
|
Why not just allow autofixes to include a new Boolean property to say if it's safe to apply as an autofix or not? It seems the mechanism for describing what needs to change, at least, is exactly the same as autofix, so I feel we should reuse that if we can. I think the difference is we would be able to have more suggestions/fixes (such as no-useless-escape, sort-keys, etc.) but only specific fixes are applied automatically. Or we could have multiple levels of fixes based on how "safe" we think they are, and autofix only applies the safest fixes. |
@platinumazure How do you think to handle multiple suggestions on |
The same way as currently: Treat them as a combined fix for collision purposes, don't apply the fix automatically if it does collide. In the case of suggestions (which I am interpreting as fixes not applied automatically in my proposal), then the suggestion isn't applied anyway. It would be up to the integration to decide how to apply the fixes. I could see us considering some quality-of-life options, such as not showing suggestions if autofixes conflict, not retrieving suggestions until all fixes are applied, etc., but I don't have anything specific in mind. |
@platinumazure No, we cannot combine two suggestions because the two are different solutions for the same error. For example, new RegExp("*\.js", "u")
// ^^
// ├ Remove the '\'. (no-useless-escape)
// └ Replace the '\' by '\\'. (no-useless-escape)
|
Oh, that's a key insight. Okay, I agree, that changes things. Maybe we could require that every report have either: Suggestions (array), fix (single fixable object), or neither. And suggestions shouldn't be automatically applied. I think now I'm on the same page as @ilyavolodin (more or less). |
@platinumazure Sorry about not providing concrete example. I was struggling to come up with simple enough example of suggestion that would be visually easy to understand. I think one problem that I see with suggestions is that they might be taken too far, as in suggest refactoring of a large chunk of code. I think that's outside of the responsibilities of ESLint. |
@mysticatea Updated again to incorporate your suggestions. Thank you very much for those, they are very helpful! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a minor suggestion. Thank you!
Moving this into final commenting stage. @eslint/eslint-tsc please take a look. |
@ilyavolodin Thank you so much for driving this! If there’s anything I can clarify about our use case for this (for React Hooks) I’d be happy to provide details. (I linked to a few issues which you can see above.) |
I'm hoping to review this in the next day or two. Any chance we could wait to merge until, say, Wednesday? (If I don't review by then, just go ahead and merge.) Sorry, I've been traveling and forgot about this RFC. |
Going to merge this in, as it doesn't seem like there are any objections. |
I see that the process for getting an RCF approved here is entirely independent of the actual implementation. @ilyavolodin, are you planning on working on the implementation of this feature, or, if not, do you know if anyone is planning on working on it? |
I don't think anyone is working on it. Would you like to? It would be an amazing contribution. |
@wdoug Unfortunately, I don't have time to work on this right now. So if you would like to give it a try, that would be great! |
I would like to help if I can. I'll see if I can get familiar enough with the codebase to get a pull request up in my free time. If you end up having time to work on it before I get something up @ilyavolodin just let me know. |
@wdoug Thanks for looking into it! |
@ilyavolodin, if you get a chance to check it out, I opened a PR for this here that could use some feedback and verification that I understood the RFC correctly. |
Summary
This RTC proposes introducing a new mechanism for providing users with suggestions. It's very similar to fixes mechanism that already exists in ESLint, but will provide ability to create multiple suggestions per rule, suggestions will not be automatically applied by using
--fix
flag, and will require user interaction. This feature will only be exposed through the ESLint API, and will not be available on the CLI.Related Issues
eslint/eslint#7873
eslint/eslint#6733 (comment)