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
prefer-const should autofix, but it didn't #10582
Comments
I think we already have autofix in this rule. There are some conditions that prevent autofix. Is there a particular use case that you think should be autofixed, but that isn't being autofixed? |
yes, I created an example should this be an enhancement, or a bugfix? |
It looks like the issue is that the code doesn't want to autofix if there are multiple declarators (under the assumption that if one declarator needs fixing but others don't, it's not clear how the fix should be applied). However, we do have logic for autofixing if a destructuring assignment is completely convertible (all variables can be const). So I could see this being treated as a bugfix, but I'll defer to others in the team. |
This feels more like an enhancement to me (the current behavior isn’t wrong—it could just be made smarter). But either way, seems like a good addition to make the change @platinumazure suggested. |
Would it be ok to take a look at this? |
Looking into this, as @platinumazure said the rule guards against autofixing multiple variable declarations found: https://github.com/eslint/eslint/blob/master/lib/rules/prefer-const.js#L324. How does it sound to update the logic of the rule to if there are multiple declarations that are ALL require statements to allow autofixing? To avoid changing the rule too much, and I think that in some situations having the dev decide how to split up the declarations is a good idea. Does this sound ok? |
@sstern6 Can you clarify how |
Sure, maybe I misunderstood, but for example. Currently this code errors out but isnt autofixed because the rule checks the length of the block and says if there are multiple declarations then let the dev decide how to handle and eslint will not autofix.
Here is where I am misunderstanding, for this ticket, we want to update the rule to autofix in all cases? My propsal was to autofix the following because all var declarations were require statements.
and to continue to allow devs to decide how to handle examples like the following.
or
Maybe could you clarify what the intended behavior is? Thanks @kaicataldo |
@sstern6 I think the ask here is to autofix multiple declarators (not to specifically fix assignments that are |
To provide more context, I believe the ask is to add an autofixer for the following case:
to
instead of just warning like it does now. Check out the demo link @aladdin-add provided above to see the warnings that are generated and how the autofix doesn't fix them (when we should be able to). |
Kk working on this. Will have a PR over the next few days. Thanks for the clarification. |
to
The text was updated successfully, but these errors were encountered: