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
Rule auto-fix variable name conflicts #13706
Comments
Hi, @fisker! When renaming a variable or introducing a new one, you could replace the whole range that represents the scope of that variable. Then, ESLint will not replace overlapping ranges in the same iteration ( As an example, some builtin rules use FixTracker helper to extend the range and thus make sure that nothing within the extended range can be fixed by other rules in the same iteration. |
@mdjermanovic Thanks for this information, I know that overlapping ranges won't apply fixes from other rule, but never thought we can extend the range to prevent this conflicts, I'll try this solution. |
@fisker maybe I relabeled this issue as a "question" too early. If you think that something could be added to ESLint core, we can certainly reopen this issue or create a new one with a concrete proposal. I think that There was a lengthy discussion about this kind of problems in #7928, and the solution at the time was to internally try out the approach with the |
That would be great. |
Reopening to discuss if we could add something to ESLint's public API. @fisker in the meantime, I'd suggest you maintain your own |
@mdjermanovic I understand that, but I'm going to use it directly for now. |
@mdjermanovic what is the expected next step here? |
I reopened this issue to discuss if it would be useful to add something to public API (since If the rule wants to fix something inside a *fix(fixer) {
// yield some fixes inside `node` ...
// extend the range to `node`:
yield fixer.insertTextBefore(node, "");
yield fixer.insertTextAfter(node, "");
} Then, the report translator will merge fixes and the unchanged code into one big fix having the range of |
Nice! So can we close this issue? |
I added a test to confirm that this works in #13748, and I'd agree to close this issue. |
All right, closing. |
The version of ESLint you are using.
v7.7.0
The problem you want to solve.
I have this code
We added a rule
unicorn/catch-error-name
with auto-fix, it will fixerr
toerror
.We are adding a new rule
prefer-ternary
, we plan to fix this code toHere is the problem, when we check variable name
error
inprefer-ternary
rule andcatch-error-name
, they will both showerror
is not used, but when apply fixes, there will be conflicts.Any solution/suggestion?
Your take on the correct solution to problem.
N/A
Are you willing to submit a pull request to implement this change?
N/A
The text was updated successfully, but these errors were encountered: