Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
prefer-const should autofix, but it didn't #10582
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.
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?
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.
Maybe could you clarify what the intended behavior is?
To provide more context, I believe the ask is to add an autofixer for the following case:
instead of just warning like it does now.