Rule for pointless assignments #17714
-
I recently have to debug a lot of old code and had some need for an ESLint that tells me when an assignment is pointless. A code example: let name = "someval"; // pointless assignment, the value is never used
if (someComplicatedCondition) {
name = "if";
} else {
name = "else";
} The following code would not violate the rule let name"; // no assignment
if (someComplicatedCondition) {
name = "if";
} else {
name = "else";
} neither would this let name = "someval"; // pointless assignment
console.log(name); // here's a read before the variable is reassigned, so it's not pointless
if (someComplicatedCondition) {
name = "if";
} else {
name = "else";
} In this example, the first assignment to So I found myself wanting a rule that finds cases of values being assigned without being read before they are reassigned. PS: Keep in mind the example above is quite obvious but the codebase I'm dealing with cases like these are less obvious. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It currently doesn't exist in the core, but a proposal for this rule has been accepted (#17559) and we are already working on it in #17625. |
Beta Was this translation helpful? Give feedback.
It currently doesn't exist in the core, but a proposal for this rule has been accepted (#17559) and we are already working on it in #17625.