Rule auto-fix variable name conflicts
See original GitHub issueThe version of ESLint you are using.
v7.7.0
The problem you want to solve.
I have this code
function foo() {
try {
} catch (err) {
console.log(err);
if (test) {
throw a;
} else {
throw b;
}
}
}
We added a rule unicorn/catch-error-name
with auto-fix, it will fix err
to error
.
function foo() {
try {
} catch (error) {
console.log(error);
if (test) {
throw a;
} else {
throw b;
}
}
}
We are adding a new rule prefer-ternary
, we plan to fix this code to
function foo() {
try {
} catch (err) {
console.log(err);
const error = test ? a : b;
throw error;
}
}
Here is the problem, when we check variable name error
in prefer-ternary
rule and catch-error-name
, they will both show error
is not used, but when apply fixes, there will be conflicts.
function foo() {
try {
} catch (error) {
console.log(error);
const error = test ? a : b; // <-- error is already used.
throw error;
}
}
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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Working with Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Resharper function to fix naming convention issues
When an inconsistent naming is detected, ReSharper underlines the symbol in question. Click on it. · Click on the light bulb. The first...
Read more >Using Prettier and ESLint to automate formatting and fixing ...
Remove conflicting rules and run serially; Run Prettier followed by ESLint programmatically; Run Prettier as an ESLint rule. First, let's get a ...
Read more >JavaScript naming conflicts: How existing code can ... - 2ality
Sometimes the name of a proposed feature (a method, a global variable, etc.) clashes with existing code and has to be changed.
Read more >Gentle Introduction To ESLint Rules - DEV Community
ESLint can determine the conflicts by inspecting the node/token range ... replaceTextRange([4, 7], "bar") // changes the var name to bar ] }....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I reopened this issue to discuss if it would be useful to add something to public API (since
FixTracker
isn’t public), but now I realized there’s a simple way to extend the fixed range using the already existing features.If the rule wants to fix something inside a
node
and make sure there will be no other fixes inside thenode
in the same pass, thefix()
can just add empty strings around thenode
:Then, the report translator will merge fixes and the unchanged code into one big fix having the range of
node
.All right, closing.